In C++ one can declare iterator on map. Then iterator can be promoted and saved, thus iteration can be resumed later from the saved position.
How to do the same in Obj-C efficiently?
In C++ one can declare iterator on map. Then iterator can be promoted and saved, thus iteration can be resumed later from the saved position.
How to do the same in Obj-C efficiently?
Try to create an ordered array with the keys of your dictionary and iterate it. You can break out from the for loop anytime. The currentIteration
var makes sure to store the last iteration, that you can use next time for resuming.
NSMutableDictionary *dictionary = @{@"key1" : @"value1", @"key2" : @"value2", @"key3" : @"value3"};
NSArray *keys = dictionary.allKeys;
int currentIteration = 0;
for (int i = 0; i < keys.count; i++) {
currentIteration = i;
NSObject *value = dictionary[keys[i]];
NSLog(@"%@", value);
}