我想使用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; )
答案 0 :(得分:1)
确保已设置fetchRequest.predicate
值(即, nil )。
帖子中的代码显示已分配predicate
值。但是,如果未设置NSFetchRequest.predicate
属性,则println控制台消息将显示((null))
值predicate
。