views:

28

answers:

1

hi all!

i have a NSDictionary with NSString and NSArray

i have to save in a variable only the NSArray without know the key.

Is Possibile?

Thx all

And sorry for my bad english

A: 

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)

David Gelhar
isMemberOfClass i don't know this method! Fantastic Thx a lot
Kazzar
You might also want to check out isKindOfClass, which covers subclasses too.
David Gelhar
I believe you'd need to use `-isKindOfClass`; `NSArray` is abstract.
jlehr
@jlehr good point; I'll edit my response
David Gelhar