开发者

objective-c: array enumeration using keypath

I have an array of Person objects (which has a number of attributes). I want to make another array with just the Person's "fullname" attribute. Is there a simple way to do this, other than the obvious one: iterate over the original array, and copy over the fullname one-by-one into another array? Can we do this initWithArray: and tell it to use the obje开发者_开发问答ct's fullname property when copying?


NSArray indeed has built-in method for that:

NSArray *nameArray = [personArray valueForKey:@"fullname"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜