I have the following code:
NSDictionary *dict = [[NSDictionary alloc]
initWithObjectsAndKeys:myarray1, @"array1", myarray2, @"array2" nil];
NSArray *shorts =[[dict allKeys] sortedArrayUsingSelector:@selector(compare:)];
for (NSString *dir in shorts) {
NSArray *tempArr = [dict objectForKey:dir];
for (NSString *file in tempArr ) {
NSLog(@"%@", file);
}
}
Where myarray1 and myarray2 are NSArrays.
When I execute the code the application crashes with:
-[NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1d134
This is apparently the tempArr, which is not recognized as an NSArray. I know that [dicFiles objectForKey:dir] returns an id type object, but as a generic type, I cannot get what I’m doing wrong.
You haven’t included the code that initializes
myarray1andmyarray2, but apparently one or both of them are instances ofNSStringrather thanNSArray. You can check that after retrieving one of the objects from the array as follows: