Reputation: 50468
I'm looking to access the keys/elements from a dictionary in random, non-repeating, order. What's the shortest bit of ios code to achieve this?
Upvotes: 0
Views: 54
Reputation: 42598
Once you have NSMutableArray's -shuffle category from canonical way to randomize an NSArray in Objective C.
NSMutableArray *suffledKeys = [[dict allKeys] mutableCopy];
[suffledKeys shuffle];
for (id randomKey in shuffledKeys) {
id randomValue = [dict objectForKey:randomKey];
// What ever you need to do.
}
Hope this helps.
Upvotes: 3