代码之家  ›  专栏  ›  技术社区  ›  emenegro

使用nspredicate按对象属性筛选

  •  3
  • emenegro  · 技术社区  · 14 年前

    我有一个可变的自定义对象数组。例如,我想按对象的属性筛选该数组 myObject.attributeOne(对象属性) .

    如何创建要与一起使用的nspredicate

    [myArrayOfObjects filterUsingPredicate:<the_predicate>]
    
    1 回复  |  直到 12 年前
        1
  •  7
  •   Raunak Agarwal    12 年前

    使用方法如下:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"FriendStatus == 1"];
    
    NSMutableArray *filtered = [MessageArray filteredArrayUsingPredicate:predicate];