如何使用ID保存核心数据?

时间:2016-12-21 22:17:35

标签: ios core-data swift3 relational-database relationship

我需要改变"点火"在指定id的coreData中,但我不能使用谓词。

func saveIgnition(){
    let predicate = NSPredicate(format: "objectNo == %@", oDriver.sObjectNo)
    let sort = NSSortDescriptor(key:"objectNo", ascending:true)
    print(oDriver.sObjectNo)
    print("is 0 o 1: ", oDriver.iIgnition)
    // we set up our entity by selecting the entity and context that we're targeting
    let entity = NSEntityDescription.insertNewObject(forEntityName: "Driver", into: oMain.moc)
    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Driver")
    fetchRequest.predicate = predicate
    fetchRequest.sortDescriptors = [sort]

    entity.setValue(self.oDriver.iIgnition, forKey: "ignition")
    do {
        try oMain.moc.save()
        fetchIgn()

    } catch {
        fatalError("Failure to save context: \(error)")
    }
}

0 个答案:

没有答案