开发者

objective-c: array enumeration using keypath

开发者 https://www.devze.com 2023-03-24 16:19 出处:网络
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 obvi

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

精彩评论

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