NSDictionary to NSArray

 

Usually I write in spanish, but since this is a universal issue (at least for the people who code in objective-c) I’m going to post this “answer” in english.

I was struggling for a couple of hours with something that in the end was very simple, trying to put the values and keys of a NSDictionary in a NSArray to order them, I’m a N00b, yes. But that’s how we all started, so hopefully in some months I will be less N00bish. I was trying at first with this code:

But when I was iterating the array

The debugger send me a error message telling me that I was in fact wrong, and the NSDictionary can’t use the objectAtIndex. Wait, what? but it’s an array!!!  Well, I was telling the NSArray at the beginning to work as a NSDictionary and I was unaware.

What I found out was that I needed to send all the values instead of using the valueForKey. And that was it. Solution served, easy indeed.

Share