0

I have the following issue, I need to get an array of values from an array of custom Objects. Is there a method for doing this without iterating the principal array, let me graphic it a little bit.

NSArray *principalArray = @[
         customObject1,customObject2,customObject3,....customObject(n)
];

This customObject instances have a properties lets say id,name,lastname. I want to get an NSArray with the value of name from the principalArray

Thanks for your help.

1 Answers1

1

EDIT:

As somebody pointed out in comments: its a duplicate of existing SO question: Getting an NSArray of a single attribute from an NSArray

There is a method for NSArray - valueForKey - with key being an attribute of your first array. This method returns you an NSArray from an NSArray.

In your case you can do the following:

NSArray *nameArray = [principalArray valueForKey:@"name"];
Community
  • 1
  • 1
Naz Mir
  • 1,028
  • 1
  • 9
  • 19