【问题标题】:NSPredicate to check for NULL, and blank strings in Core DataNSPredicate 用于检查核心数据中的 NULL 和空白字符串
【发布时间】:2014-03-24 16:20:40
【问题描述】:

由于不支持 CoreData 长度,CoreData 将谓词 name.length > 1 转换为 sqlite in name > 1... 虽然它应该是 length(name) > 1。

我们可以使用这个: [NSPredicate predicateWithFormat:@"NOT name MATCHES '^\s*$'"];

但是正则表达式的计算成本会更高(比计算正则表达式花费的时间比简单的相等要长)。

那么我该怎么做。有什么好主意吗?

【问题讨论】:

    标签: core-data ios7 nspredicate nsexpression predicatewithformat


    【解决方案1】:

    请转至CoreData predicate: string property length?

    或者你可以这样做

    NSString *attributeName = @"name";
    NSString *attributeValue = [NSString stringWithFormat:@".{%d}", 5];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K MATCHES %@", attributeName, attributeValue];
    

    参考 - NSPredicate for an NSManagedObject's string attribute's length

    【讨论】:

    • 我不想检查它的长度是否大于5。我只想检查它的长度是否>0。
    猜你喜欢
    • 2011-11-14
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    相关资源
    最近更新 更多