iOS之谓词详解

来源:互联网 发布:a star算法的流程图 编辑:程序博客网 时间:2024/06/17 12:27

 NSArray *testArray = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"zhaojunshabi"ofType:@"plist"]];

    //创建一个谓词对象用谓词对象来指定筛选的范围

    NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"name ENDSWITH 'a'"];

    for (NSDictionary *dictin testArray) {

        if ([predicate evaluateWithObject:dict]) {

            NSLog(@"%@ %@",dict[@"name"],dict[@"age"]);

        }

    }

//把筛选的内容放在数组里面

    NSArray *fliter = [testArray filteredArrayUsingPredicate:predicate];

    NSLog(@"saaa%@",filter);

  /**逻辑运算符         * and  /&&:与         * or   /||:或         * not  /!:非         **/
  beginswitch 以什么为开头
endswitch 以什么为结尾 
条件判断尽量用大写 为了易懂  还有其他的一些不做详解 


0 0
原创粉丝点击