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?
Asked
Active
Viewed 46 times
1 Answers
3
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.

Community
- 1
- 1

Jeffery Thomas
- 42,202
- 8
- 92
- 117