【问题标题】:CoreData/SQLite fastest way to determine if a field doesn't end with a particular stringCoreData/SQLite 确定字段是否以特定字符串结尾的最快方法
【发布时间】:2010-09-25 02:31:45
【问题描述】:

我正在使用由 SQLite 支持的 CoreData,我正在尝试找到最快的方法来排除 AirDate 字段以 -00-00 结尾的行

我注意到了

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

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

我还能做其他优化吗?谢谢!

【问题讨论】:

    标签: objective-c cocoa sqlite core-data


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:
      [NSPredicate predicateWithFormat:@"NOT AirDate CONTAINS %@", @"-00-00"]
      

      在我的测试中是最快的,所以我就这么做了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 2014-02-09
        • 1970-01-01
        • 2016-05-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多