Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you have a dangling or wild pointer.</p> <p>You can consider Objective-C objects as pointers to structs.</p> <p>You can then of course compare them with <code>NULL</code>, or with other pointers.</p> <p>So:</p> <pre><code>( myDict == NULL ) </code></pre> <p>and</p> <pre><code>( myDict == [ NSNull null ] ) </code></pre> <p>are both valid.</p> <p>The first one will check if the pointer is <code>NULL</code>. <code>NULL</code> is usually defined as a <code>void *</code> with a value of 0.<br /> Note that, for Objective-C objects, we usually use <code>nil</code>. <code>nil</code> is also defined as a <code>void *</code> with a value of 0, so it equals <code>NULL</code>. It's just here to denote a <code>NULL</code> pointer to an object, rather than a standard pointer.</p> <p>The second one compares the address of <code>myDict</code> with the singleton instance of the <code>NSNull</code> class. So you are here comparing two pointers values.</p> <p>So to quickly resume:</p> <pre><code>NULL == nil == Nil == 0 </code></pre> <p>And as <code>[ NSNull null ]</code> is a valid instance:</p> <pre><code>NULL != [ NSNull null ] </code></pre> <p>Now about this:</p> <pre><code>( [ myDict count ] == 0 ) </code></pre> <p>It may crash if you have a wild pointer:</p> <pre><code>NSDictionary * myDict; [ myDict count ]; </code></pre> <p>Unless using ARC, it will surely crash, because the <code>myDict</code> variable has not been initialised, and may actually point to anything.</p> <p>It may also crash if you have a dangling pointer:</p> <pre><code>NSDictionary * myDict; myDict = [ [ NSDictionary alloc ] init ]; [ myDict release ]; [ myDict count ]; </code></pre> <p>Then you'll try to send a message to a deallocated object.<br> Sending a message to <code>nil</code>/<code>NULL</code> is always valid in Objective-C.</p> <p>So it depends if you want to check if a dictionary is <code>nil</code>, or if it doesn't have values (as a valid dictionary instance may be empty).</p> <p>In the first case, compare with <code>nil</code>. Otherwise, checks if count is 0, and ensure you're instance is still valid. Maybe you just forgot a retain somewhere.</p>
    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.
    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