开发者

Access an object in an NSArray using a key path

开发者 https://www.devze.com 2023-04-07 11:24 出处:网络
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 be

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

精彩评论

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

关注公众号