码迷,mamicode.com
首页 > 其他好文 > 详细

NSPredicate的使用

时间:2014-12-18 15:25:12      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:ios   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的使用

标签:ios   nspredicate   

原文地址:http://roderickkennedy.blog.51cto.com/6758427/1591348

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!