【问题标题】:CoreData NSPredicate date() functionCoreData NSPredicate date() 函数
【发布时间】:2014-09-03 23:20:02
【问题描述】:

我正在尝试使用以下谓词:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < date('now')", nil];

但我收到了NSInvalidArgumentException', reason: 'Unable to parse function name 'date:' into supported selector (date:) ',所以我猜可能 iOS 版本的 SQLite

不支持 date('now')

我该怎么做?

【问题讨论】:

    标签: ios core-data


    【解决方案1】:

    你可以试试这个……

    NSDate *dateNow = [NSDate date];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < %@", dateNow];
    

    【讨论】:

      【解决方案2】:

      你现在应该使用 NSExpression 而不是日期:

      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < now", nil];
      

      【讨论】:

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