I wrote a method to search for people in address book, and I want the method to be able to find "john bigs" even if I call the method [someAdressBook searchName:@"joh"];
.
My method works for full names, but Im having issues in the partial names, this is my code:
-(NSMutableArray *) searchName:(NSString *) someName{
NSRange range;
NSMutableArray *results = [[NSMutableArray alloc] init];
for (AddressCards *addressCard in book)
{
if (someName != nil && [someName caseInsensitiveCompare:addressCard.name] == NSOrderedSame)
[results addObject:addressCard.name];
else {
range = [addressCard.name rangeOfString:someName];
if (range.location != NSNotFound)
[results addObject:addressCard.name];
}
}
NSLog(@"%@", results);
return results;
}
Please help me get this right.