首页 > 代码库 > NSPredicate的使用

NSPredicate的使用

    NSArray * arrayFilter = [NSArray arrayWithObjects:@"pict", @"blackrain", @"ip", nil];

    

    NSMutableArray *arrayContents = [NSMutableArray arrayWithObjects:@"I am a picture.", @"I am a guy", @"I am gagaga", @"ipad", @"iphone", nil];

    

    int i = 0;

    NSInteger count = [arrayFilter count];

    

    for(i = 0; i < count; i ++)

        

    {

        

        NSString * arrayItem = (NSString *)[arrayFilter objectAtIndex:i];

        

        NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", arrayItem];

        NSLog(@"Filtered array with filter %@, %@", arrayItem, [arrayContents filteredArrayUsingPredicate:filterPredicate]);

                                        

    }

    

    NSArray *arrayFilter01 = [NSArray arrayWithObjects:@"abc1", @"abc2", nil];

    

    NSMutableArray *arrayContent01 = [NSMutableArray arrayWithObjects:@"a1", @"abc1", @"abc4", @"abc2", nil];

    

    NSPredicate * thePredicate = [NSPredicate predicateWithFormat:@"NOT (SELF in %@)", arrayFilter01];


    [arrayContent01 filterUsingPredicate:thePredicate];

    NSLog(@"result%@",arrayFilter01);


本文出自 “深圳市联城通科技公司” 博客,谢绝转载!

NSPredicate的使用