Reputation: 1442
I have a NSDictionary
with a NSString
and NSArray
I have to save only the NSArray
in a variable without knowing the key.
Is this possible?
Upvotes: 0
Views: 101
Reputation: 27900
If I'm understanding you correctly, you have a dictionary that contains both an NSString and an NSArray, and you want to extract just the NSArray, without knowing what the key is.
One way to do that is to look through the dictionary with fast enumeration:
NSString *key;
for(key in someDictionary){
id someObject = [someDictionary objectForKey: key];
}
and then look at the objects to see which one is an NSArray:
if ([someObject isKindOfClass:[NSArray class]]) {
// do something with the array
}
(obligatory warning: explicitly checking an object's class is often a sign of a flawed design. In most cases, you should be checking for behavior (-respondsToSelector
), not class identity)
Upvotes: 1