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.
精彩评论