我有一个包含如下字段的数据库
纬度经度标志 54.1425 98.2564 0 52.1036 94.1458 3 51.1569 92.1458 3 50.1326 91.1458 3 56.1236 93.1458 0
我需要检索标记为 3 的记录。
let fetchRequest = NSFetchRequest()
let appDelegate =
UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let entityDescription = NSEntityDescription.entityForName("TABLE_LOCATION", inManagedObjectContext: managedContext)
// Configure Fetch Request
fetchRequest.entity = entityDescription
do {
let result = try managedContext.executeFetchRequest(fetchRequest)
//print(result)
} catch {
let fetchError = error as NSError
print(fetchError)
}
我所拥有的只是上面的代码,它从表 TABLE_LOCATION 中检索所有记录,非常感谢任何代码或工作示例
谢谢!
最佳答案
您需要将 NSPredicate 添加到您的 fetchRequest。
fetchRequest.predicate = NSPredicate(format: "flag == %@", "3")
关于swift - 如何检索满足条件 swift 2 的 CoreData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36262618/