NSMutableArray check if object already exists

前端 未结 9 1451
傲寒
傲寒 2020-12-25 10:17

I am not sure how to go about this. I have an NSMutableArray (addList) which holds all the items to be added to my datasource NSMutableArray.

I now

9条回答
  •  悲哀的现实
    2020-12-25 10:37

    Use NSPredicate.

    NSArray *list = [[appDelegate.list copy] autorelease];
    
    for (Item *item in addList) {
    
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"iName MATCHES %@", item.iName];
        NSArray *filteredArray = [list filteredArrayUsingPredicate:predicate];
        if ([filteredArray count] > 0) [appDelegate insertItem:item];
    }
    

提交回复
热议问题