【问题标题】:NSArray with NSPredicate using NOT INNSArray 和 NSPredicate 使用 NOT IN
【发布时间】:2012-01-24 17:27:34
【问题描述】:

我有一个 NSArray,我想使用 NSPredicate 过滤掉某些对象,我希望我可以使用 NOT IN,因为我看到我可以轻松地执行 IN。

所以我有我的数组:

self.categoriesList

然后我得到我想要删除的值:

NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"];

这为我提供了我不想显示的类别的 ParentCategoryID 列表,所以我想我可以使用 NSPredicate 来删除它们:

self.cateoriesList = [self.cateoriesList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"CategoryID NOT IN %@",parentIDs]];

这失败了:

reason: 'Unable to parse the format string "CategoryID NOT IN %@"'

如果我只想使用 IN 当然可以完美运行。

【问题讨论】:

    标签: ios objective-c nsarray nspredicate


    【解决方案1】:

    NONE怎么样?

    [NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs];
    

    【讨论】:

    【解决方案2】:

    NOT (CategoryID IN %@) 呢?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多