I am trying to copy the objects content of a NSDictionary to a NSMutableArray, and I am using the following code :
// Use when fetching binary data
NSData *responseData = [request responseData];
// View the data returned - should be ready for parsing.
resultsDictionary = [responseData objectFromJSONData];
NSLog(@"ResultsDictionary:%@", resultsDictionary);
self.OnlineObjects = [[[NSMutableArray alloc] init] autorelease];
for (NSDictionary * dataDict in resultsDictionary) {
[OnlineObjects insertObject:dataDict atIndex:0];
}
NSLog(@"OnlineObjects:%@", OnlineObjects);
This is working as i am getting all objects from the Dictionary, but the objects order have been revers, first object is now last …
How can tell the insertObject to add the object at the last index ?
Thanks
You can use the
addObject:method instead.To get rid of the hash order problem get
allKeys, sort the array and then use the elements as keys to get the objects in proper order.Verbose example (for integer keys):