1

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 object's fullname property when copying?

1 Answer 1

9

NSArray indeed has built-in method for that:

NSArray *nameArray = [personArray valueForKey:@"fullname"];
Sign up to request clarification or add additional context in comments.

1 Comment

Isnt valueForKeyPath an NSDictionary method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.