{"id":240,"date":"2011-11-17T22:40:03","date_gmt":"2011-11-17T22:40:03","guid":{"rendered":"http:\/\/phyline.com\/blog\/?p=240"},"modified":"2015-08-01T15:21:04","modified_gmt":"2015-08-01T15:21:04","slug":"nsdictionary-to-nsarray","status":"publish","type":"post","link":"http:\/\/sophyonline.com\/blog\/2011\/11\/nsdictionary-to-nsarray\/","title":{"rendered":"NSDictionary to NSArray"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Usually I write in spanish, but since this is a universal issue (at least for the people who code in objective-c) I&#8217;m going to post this &#8220;answer&#8221; in english.<\/p>\n<p>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&#8217;m a N00b, yes. But that&#8217;s how we all started, so hopefully in some months I will be less N00bish. I was trying at first with this code:<\/p>\n<pre>\u00a0NSArray *array = [dictionary valueForKey:@\"Root\"];<\/pre>\n<p>But when I was iterating the array<\/p>\n<pre>for (int i=0;i&lt;=[array count];i++){\r\n   NSDictionary *item = [array objectAtIndex:i];\r\n}<\/pre>\n<p>The debugger send me a error message telling me that I was in fact wrong, and the NSDictionary can&#8217;t use the objectAtIndex. Wait, what? but it&#8217;s an array!!! \u00a0Well, I was telling the NSArray at the beginning to work as a NSDictionary and I was unaware.<\/p>\n<p>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.<\/p>\n<pre>NSArray *array = [dictionary allValues];<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Usually I write in spanish, but since this is a universal issue (at least for the people who code in objective-c) I&#8217;m going to post this &#8220;answer&#8221; 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 class=\"read-more\" href=\"http:\/\/sophyonline.com\/blog\/2011\/11\/nsdictionary-to-nsarray\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[],"tags":[],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":10,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":657,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/240\/revisions\/657"}],"wp:attachment":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}