I have two functions:
which returns an array that is filled with a block
- (NSArray *)getArray { NSArray *someValues = @[@0, @42, @23, @5, @8, @2013]; NSArray *filter = @[@42, @23, @5]; //replacing this NSMutableOrderedSet with a NSMutableArray //and return just matched then, resolves the problem. //so the exception has to do something with that set. NSMutableOrderedSet *matched = [[NSMutableOrderedSet alloc] init]; for (id value in someValues) { [filter enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isEqual:value]) [matched addObject:value]; }]; } return [matched array]; }
and another one that lists the returned array from the first method
- (void)enumArray:(NSArray *)array { NSEnumerator *enumerator = [array objectEnumerator]; for (id obj in enumerator) { if ([obj isEqual:@42]) [enumerator nextObject];
If now I do something like this
NSArray *array = [foo getArray]; [foo enumArray:array];
i will receive an NSGenericException with the following message:
The collection <__ NSOrderedSetArrayProxy: 0x123456> was mutated while enumerated
where the hell something mutated. I do not understand. returning a copy from this array solves the problem, but I still don't understand.
The error has something with NSMutableOrderedSet, if I replace the set with an array, I do not get an exception.
some screenshots, exception thrown

