-1

after a decent search and could not find solution (probably i missed something...):

i have an array with objects, the object is AddressCard and one if the properties is name.

so i send to my function string and with for statement looking all the matches inside my object collection array who contain AddressCArd object (bookArray) and if there is match i want to add this object to an array asnd return this array:

-(NSMutableArray *) lookup:(NSString *) name
{
    NSMutableArray arr = [NSMutableArray array];

    for(AddressCard *card in bookArray}
    {
        if([card.name rangeOfString: name].location == NSNotfound)
        {
             [arr addObject: card];
        }  
    }

    return arr;
}
4

1 回答 1

1

You can do as this:

-(NSMutableArray *) lookup:(NSString *) name {
    NSMutableArray *arr = [NSMutableArray array];
    for(AddressCard *card in bookArray) {
        //if([card.name isEqualToString:name]) {
        if([[card.name capitalizedString] rangeOfString:[name capitalizedString]].location != NSNotFound)
             [arr addObject:card];
        }  
    }
    return arr;
}
于 2013-03-30T05:52:02.953 回答