Create a predicate (the following assumes your Person
class has the name
and number
properties of the string):
NSString *nameFilter = @"Steve*"; NSString *numberFilter = @"555-*"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"(name like %@) or (number like %@)", nameFilter, numberFilter];
Then filter the array (assuming you have an NSArray
of Person
objects):
NSArray *personArray = ; NSArray *filtered = [personArray filteredArrayUsingPredicate:pred];
The result will be an array containing Person
objects whose name
can be "Steve", "Steven", etc., and the number of which begins with 555-
.
Edit
What you are saying does not really make sense. You cannot remove properties from a class (or rather should not). If you need an array containing only names and numbers that you will need to iterate through an array of Person
objects:
NSMutableArray *result = [NSMutableArray array]; for (Person *p in personArray) [result addObject:[NSString stringWithFormat:"%@ : %@", [p name], [p number]]];
dreamlax
source share