开发者

Access an object in an NSArray using a key path

I've read through the KVC docs on Apple and it talks in depth about making your indexed collections accessible through key value cod开发者_JAVA技巧ing, but I can't find any examples of a key path being used to access an arbitrary element within the array.

If my Blob class has an NSArray *widgets, I'd like to be able to get the widget at index 4 by doing something like:

[myBlob valueForKeyPath:@"widgets[4]"]

Is there anything like this?


myBlob answers to 'valueForKey:' and widgets being an NSArray answers to 'objectAtIndex:'. So '[[myBlob valueForKey:@"widgets"] objectAtIndex:4]' should do the trick.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜