开发者

Save part of NSDictionary

I have a NSDictionary with a NSString 开发者_JS百科and NSArray

I have to save only the NSArray in a variable without knowing the key.

Is this possible?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜