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

CoreData/SQLite确定字段是否以特定字符串结尾的最快方法

  •  1
  • BarrettJ  · 技术社区  · 14 年前

    我注意到了

    [NSPredicate predicateWithFormat:@"NOT AirDate CONTAINS %@", @"-00-00"]
    

    比…快得多

    [NSPredicate predicateWithFormat:@"NOT AirDate LIKE %@", @"*-00-00"]
    

    2 回复  |  直到 14 年前
        1
  •  0
  •   Sven    14 年前

    您可以尝试使用正则表达式:

    [NSPredicate predicateWithFormat:@"NOT AirDate MATCHES %@", @"-00-00$"]
    

    但你应该用 NSDate 而不是将日期存储为字符串。使用日期比较而不是匹配字符串进行搜索应该会更快。

        2
  •  0
  •   BarrettJ    14 年前
    [NSPredicate predicateWithFormat:@"NOT AirDate CONTAINS %@", @"-00-00"]