2
我想存儲一個有28個條目的數組到我的coreData。有沒有辦法做到這一點? 我用這段代碼試過了,但看起來這段代碼只是重寫了這個值。在CoreData中的Swift數組
let appDelegate =
UIApplication.shared.delegate as! AppDelegate
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "PillTook",
in:managedContext)
let value = NSManagedObject(entity: entity!,
insertInto: managedContext)
for var index in 0...27 {
value.setValue(false, forKey: "took")
do {
try managedContext.save()
pillTook.append(value)
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
}
非常感謝:) –