views:

35

answers:

1

Hello, 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 following 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 a NSArray... I know that [dicFiles objectForKey:dir] return an 'id' type object but as a generic type , i cannot get what i'm doing wrong ...

Any help appreciated

+1  A: 

You haven't included the code that initializes myarray1 and myarray2, but apparently one or both of them are instances of NSString rather than NSArray. You can check that after retrieving one of the objects from the array as follows:

if (![tempArr isKindOfClass:[NSArray class]])
{
    NSLog(@"Unable to process temp array because it's an instance of %@", [tempArr class]);
}
else
{
    // for loop code goes here...
}
jlehr
This did the trick....you were right , it was my mistake
Kostas.N
When you see an 'unrecognized selector' error message, you're in luck, because the message tells you exactly what went wrong. In this case the framework was trying to send a private variant of `-count` -- an `NSArray` message -- to an instance of `NSCFString` (a private subclass of `NSString`).
jlehr
Many thaks for this notice ! Its really helpful
Kostas.N