"with fast enumeration and an nsdictionary, iterating in the order of the keys is not guaranteed – how can i make it so it is in order?" Code Answer

2

one way could be to get all keys in a mutable array:

nsmutablearray *allkeys = [[dictionary allkeys] mutablecopy];

and then sort the array to your needs:

[allkeys sortusingcomparator: ....,]; //or another sorting method

you can then iterate over the array (using fast enumeration here keeps the order, i think), and get the dictionary values for the current key:

for (nsstring *key in allkeys) {
   id object = [dictionary objectforkey: key];
   //do your thing with the object 
 }
By Matthew Grivich on May 29 2022

Answers related to “with fast enumeration and an nsdictionary, iterating in the order of the keys is not guaranteed – how can i make it so it is in order?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.