【问题标题】:NSPredicate and ignore strings with specified format Objective cNSPredicate 并忽略指定格式的字符串 Objective c
【发布时间】:2019-11-18 14:13:22
【问题描述】:

我有一个包含以下值的数组:

<__NSArrayM 0x1c804f120>(
Model.sqlite,
Model.sqlite-shm,
Model.sqlite-wal,
iiii,
report,
test,
ttrrr,
tyyyy,
ww,
wwww
)

我想 NSPredicate 数组并忽略任何具有字符串格式 .sqlite 的数组内容并打印如下所示:

<__NSArrayM 0x1c804f120>(
iiii,
report,
test,
ttrrr,
tyyyy,
ww,
wwww
)

我想知道 NSPredicate 是哪一个能做到这一点。

【问题讨论】:

    标签: ios objective-c nsarray nspredicate


    【解决方案1】:

    可以使用NOT CONTAINS,查询.sqlite字符串过滤掉

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF CONTAINS %@)", @".sqlite"];
    

    【讨论】:

      【解决方案2】:

      找到解决办法:

      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF contains[c] %@)",@".sqlite"];
      

      【讨论】:

      • 不需要NSString stringWithFormat:。只需:NSPredicate* predicate1 = [NSPredicate predicateWithFormat:@"NOT (SELF contains[c] %@)", @"Model.sqlite"];
      猜你喜欢
      • 1970-01-01
      • 2012-04-22
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多