<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2011-08-05-method-signature-mismatches.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 04:37:07 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Cedric Luthi - 2011-08-17 09:27:03</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>For a great example of passing variable arguments when the method expects fixed arguments that does not work, have a look at &lt;a href="https://gist.github.com/937908"&gt;https://gist.github.com/937908&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;This undefined behavior happens with the gcc version that comes with Xcode 3.2.6</description><guid isPermaLink="true">fd3fa9b918b455d7b45b6b3a61e8f889</guid><pubDate>Wed, 17 Aug 2011 09:27:03 GMT</pubDate></item><item><title>mikeash - 2011-08-07 14:29:16</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>If you cast the receiver of the message to the correct class, then that will indeed solve the problem. It's ugly, but if you need to do it then it gets the job done.
&lt;br /&gt;
&lt;br /&gt;This is actually a pretty common pattern when multiple init methods exist with the same name but different signatures:
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[[SomeClass alloc] initWithThingy: 7]; // warns because +alloc returns id
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[(SomeClass *)[SomeClass alloc] initWithThingy: 7]; // works
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;Fortunately, Apple's newer compilers are becoming smart enough to know that +alloc returns an instance of its receiver, so this particular example is going away.</description><guid isPermaLink="true">7803f950db9e8bfa9b216dcbe45715be</guid><pubDate>Sun, 07 Aug 2011 14:29:16 GMT</pubDate></item><item><title>groue - 2011-08-07 04:50:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>I did not dig deep in that subject, but once in a while, I remember having explicitly casted to the class owning the intended selector, in order to avoid compiler warnings (and I never had runtime problems). ... So I cargo-cult-induced that this cast was enough to let the compiler generate the correct code. What do you think?</description><guid isPermaLink="true">0d66d061e0b01f1854134756ebb4a2b0</guid><pubDate>Sun, 07 Aug 2011 04:50:14 GMT</pubDate></item><item><title>mikeash - 2011-08-05 20:58:55</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>Right, Java is in the same category as Objective-C, as a mostly OO language with non-OO parts.</description><guid isPermaLink="true">a21b2d0434bed94a990fb160b644c1ac</guid><pubDate>Fri, 05 Aug 2011 20:58:55 GMT</pubDate></item><item><title>Kelvin Kao - 2011-08-05 19:50:39</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>So I guess Java can't be considered a true object oriented language then? It also uses C-like primitives...</description><guid isPermaLink="true">9dcbd4d8ad3b1bb782e7bb992a5f72a5</guid><pubDate>Fri, 05 Aug 2011 19:50:39 GMT</pubDate></item><item><title>Scott - 2011-08-05 19:00:29</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>a further note: signatures and integer sizes are more fun when you use classdump.
&lt;br /&gt;
&lt;br /&gt;If one happens to be using private APIs (which of course, none of us would do) and using ClassDump to get the headers, you have to be extra careful because generating a classdump on different architectures may return different signatures -- especially with NSInteger and its kin because class dump will return the size used for the architecture and not NSInteger.
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;if classdump i386 show a int, and classdump x86_64 shows a long long, then the header should be an NSInteger.
&lt;br /&gt;
&lt;br /&gt;If i386 shows a int and x86_64 shows an int, then the header should be an int
&lt;br /&gt;
&lt;br /&gt;If i386 shows a long long and x86_64 shows an long long, then the header should be an long long
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">fb08234b4bc28bc4aa1fae42551ce008</guid><pubDate>Fri, 05 Aug 2011 19:00:29 GMT</pubDate></item><item><title>mikeash - 2011-08-05 17:20:44</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>Really, the entire existence of &lt;code&gt;NSNumber&lt;/code&gt; is due to the C heritage. In true object oriented languages, like Smalltalk and many others, there's no need for classes like &lt;code&gt;NSNumber&lt;/code&gt; because there are no primitives, and the language's built-in numbers are already objects.</description><guid isPermaLink="true">062e9d615b9261c7144159d340af0f64</guid><pubDate>Fri, 05 Aug 2011 17:20:44 GMT</pubDate></item><item><title>Jesper - 2011-08-05 17:11:51</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-08-05-method-signature-mismatches.html#comments</link><description>It's a very interesting point that maybe some methods have selectors like numberWithUnsignedLongLong: simply because they have to. The name Objective-C belies how much of the "objective" part is shaped by the "C".</description><guid isPermaLink="true">0178dda22c6110dbee1291ee063e6190</guid><pubDate>Fri, 05 Aug 2011 17:11:51 GMT</pubDate></item></channel></rss>
