NSPredicate等于NSFetchRequest中的nil

时间:2015-09-01 10:55:15

标签: ios swift core-data nspredicate

我想使用NSPredicate从Core Data中获取对象。我做到了,但是当我启动NSFetchRequest时,NSPredicate等于控制台中显示的nil。我有Xcode 6.4,Swift 1.2。我重新启动了Xcode,但得到了相同的结果。我该怎么做?

func fetchRequest() -> NSFetchRequest {
    let fetchRequest = NSFetchRequest(entityName: "Car")
    let sortDescriptor = NSSortDescriptor(key: "personCar", ascending: true)
    fetchRequest.predicate = NSPredicate(format: "personRelationship.namePerson contains[c] %@", currentPerson)
    fetchRequest.fetchBatchSize = 50
    fetchRequest.sortDescriptors = [sortDescriptor]
    println(fetchRequest)
    return fetchRequest
}

来自控制台的消息

<NSFetchRequest: 0x1700db040> (entity: Car; predicate: ((null)); sortDescriptors: ((
    "(personCar, ascending, compare:)"
)); batch size: 50; type: NSManagedObjectResultType; )

1 个答案:

答案 0 :(得分:1)

确保已设置fetchRequest.predicate值(即, nil )。

帖子中的代码显示已分配predicate值。但是,如果未设置NSFetchRequest.predicate属性,则println控制台消息将显示((null))predicate