views:

99

answers:

2

Is there a way in Objective-C to search an array of objects by the contained object's properties if the properties are of type string?

For instance, I have an NSArray of Person objects. Person has two properties, NSString *firstName and NSString *lastName.

What's the best way to search through the array to find everyone who matches 'Ken' anywhere in the firstName OR lastName properties?

+1  A: 

You'll have to do a linear search, comparing each entry in the array to see if it matches what you're looking for.

progrmr
+7  A: 

Short answer: NSArray:filteredArrayUsingPredicate:

Long answer: Predicate Programming Guide

Jaanus
I like your answer better than mine.
progrmr
That worked GREAT for me. Thanks!
randombits