I created a method to search for people in an address book, and I want to return the result as an array, and if there are result to print them out, else to print "Not found".
From some reason I can print the result if the array is not nil, but the else is not working...it's not even giving me eror, this is the code:
main.m
NSMutableArray *result = [[NSMutableArray alloc] init];
result = [myBook searchName:@"jack"];
if (result != nil){
for (AddressCards *nextCard in result)
NSLog(@"%@ %@", nextCard.name, nextCard.email);
}
else
NSLog(@"Not found");
AdressBook.m
-(NSMutableArray *) searchName:(NSString *) someName{
NSMutableArray *namsFound = [[NSMutableArray alloc] init];
for (AddressCards *addressCard in book){
if ([addressCard.name rangeOfString:someName options:NSCaseInsensitiveSearch].location != NSNotFound)
[namsFound addObject:addressCard];
}
return namsFound;
}
Thank you