Note that there are some explanatory texts on larger screens.

plurals
  1. POExample of [NSDictionary getObjects:andKeys:]
    primarykey
    data
    text
    <p>I couldn't find a working example of the method <code>[NSDictionary getObjects:andKeys:]</code>. The only <a href="http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg24959.html" rel="noreferrer">example</a> I could find, doesn't compile. I provided the errors/warnings here in case someone is searching for them.</p> <p>The reason I was confused is because most methods on NSDictionary return an <code>NSArray</code>. However, in the <a href="http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDictionary/getObjects:andKeys:" rel="noreferrer">documentation</a> it states that the out variables of this method are returned as C arrays.</p> <p>Here are the error messages/warnings you might get if you follow the linked example:</p> <pre><code>NSDictionary *myDictionary = ...; id objects[]; // Error: Array size missing in 'objects' id keys[]; // Error: Array size missing in 'keys' [myDictionary getObjects:&amp;objects andKeys:&amp;keys]; for (int i = 0; i &lt; count; i++) { id obj = objects[i]; id key = keys[i]; } </code></pre> <p>.</p> <pre><code>NSDictionary *myDictionary = ...; NSInteger count = [myDictionary count]; id objects[count]; id keys[count]; [myDictionary getObjects:&amp;objects andKeys:&amp;keys]; // Warning: Passing argument 1 of 'getObjects:andKeys:' from incompatible pointer type. for (int i = 0; i &lt; count; i++) { id obj = objects[i]; id key = keys[i]; } </code></pre> <p>I'll provide a working solution as an answer to this question.</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.
 

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