Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A message sent to a <code>nil</code> object is perfectly acceptable in Objective-C, it's treated as a no-op. There is no way to flag it as an error because it's not an error, in fact it can be a very useful feature of the language.</p> <p>From the <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjectiveC/Articles/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW7" rel="noreferrer">docs</a>:</p> <blockquote> <p><strong>Sending Messages to nil</strong></p> <p>In Objective-C, it is valid to send a message to nil—it simply has no effect at runtime. There are several patterns in Cocoa that take advantage of this fact. The value returned from a message to nil may also be valid:</p> <ul> <li><p>If the method returns an object, then a message sent to <code>nil</code> returns <code>0</code> (<code>nil</code>), for example:</p> <p><code>Person *motherInLaw = [[aPerson spouse] mother];</code></p> <p>If <code>aPerson</code>’s <code>spouse</code> is <code>nil</code>, then <code>mother</code> is sent to <code>nil</code> and the method returns <code>nil</code>.</p></li> <li><p>If the method returns any pointer type, any integer scalar of size less than or equal to <code>sizeof(void*)</code>, a <code>float</code>, a <code>double</code>, a <code>long double</code>, or a <code>long long</code>, then a message sent to <code>nil</code> returns <code>0</code>.</p></li> <li><p>If the method returns a <code>struct</code>, as defined by the Mac OS X ABI Function Call Guide to be returned in registers, then a message sent to <code>nil</code> returns <code>0.0</code> for every field in the data structure. Other <code>struct</code> data types will not be filled with zeros.</p></li> <li><p>If the method returns anything other than the aforementioned value types the return value of a message sent to nil is undefined.</p></li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload