NSPredicate with strings似乎不会返回结果

时间:2014-10-28 18:40:26

标签: ios xcode core-data swift nspredicate

func getFetchRequest(#entityName: String, address value: String) -> NSFetchRequest {
    var fetch = NSFetchRequest(entityName: entityName)
    fetch.predicate = NSPredicate(format: "address = %s", value)
    println(fetch)
    return fetch
}

问题是它正在使用Xcode< 6.1并停止使用6.1。

传递getFetchRequest(entityName: "Entity", address: "test")给出以下内容

(
    entity: Entity;
    predicate: (address == "s");
    sortDescriptors: ((null));
    type: NSManagedObjectResultType;
)

1 个答案:

答案 0 :(得分:0)

Solution found in another answer可能会计算此副本。

<强>解决方案

NSPredicate(format: "address = %s", value)

应该是:

NSPredicate(format: "address = %@", value)