美文网首页谓词正则
iOS-谓词、模糊查询

iOS-谓词、模糊查询

作者: 亦晴工作室 | 来源:发表于2016-08-24 14:35 被阅读212次
    // 准备数据
        NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:30];
        for (NSInteger i = 0; i < 30; i++) {
            NSString *name = [NSString stringWithFormat:@"1000phone%04d", arc4random_uniform(10000)];
            NSInteger age = arc4random_uniform(20) + 15;
            Person *p = [Person personWithName:name age:age];
            [arrayM addObject:p];
        }
       
        NSMutableArray *array = [NSMutableArray array];
        NSLog(@"初始结果 - %@", arrayM);
     
        //新建好的谓词语句 beginwith  between
        NSString *pstringt = [NSString stringWithFormat: @" name BEGINSWITH '1000phone' && name contains '0' && age BETWEEN {%d,%d} ",28,30];
       
     //       NSString *pstringt = @" name BEGINSWITH '1000phone' && age >=26  ";
       
       
       NSPredicate * predidate = [NSPredicate predicateWithFormat:pstringt];
        //进行谓词匹配
        NSArray *array2 =[arrayM filteredArrayUsingPredicate:predidate];
       
        NSLog(@"-----%@",array2);
    

    相关文章

      网友评论

        本文标题:iOS-谓词、模糊查询

        本文链接:https://www.haomeiwen.com/subject/roqosttx.html