As suggested by Ammal i changed the code so this is the current version:
-(NSDictionary *)groupUsingBlock:(id<NSCopying> (^)(id obj))block {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (id obj in self) {
id<NSCopying> key = block(obj);
if (! dictionary[key]) {
NSMutableArray *arr = [NSMutableArray array];
dictionary[key] = arr;
}
[dictionary[key] addObject:obj];
}
return [dictionary copy];
}
I've tryed even a concurrent version, but unfortunately doesn't works
-(NSDictionary *)groupUsingBlockOptimized:(id<NSCopying> (^)(id obj))block {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id obj, NSUInteger idx, BOOL *stop){
id<NSCopying> key = block(obj);
if (! dictionary[key]) {
NSMutableArray *arr = [NSMutableArray array];
dictionary[key] = arr;
}
[dictionary[key] addObject:obj];
}];
return [dictionary copy];
}