How do you update a CoreData entry that has already been saved in Swift?

后端 未结 14 2736
有刺的猬
有刺的猬 2020-11-30 00:55

I\'m not sure what I\'m doing wrong here, but when I save the first time into coredata, it works just fine. When I try to overwrite that, it doesn\'t.

func t         


        
14条回答
  •  广开言路
    2020-11-30 01:55

     var context:NSManagedObjectContext = appDel.managedObjectContext!
    
     var en = NSEntityDescription.entityForName("ENTITIES_NAME", inManagedObjectContext: context)
    
     let batchUpdateRequest = NSBatchUpdateRequest(entity: en!)
                batchUpdateRequest.resultType = NSBatchUpdateRequestResultType.UpdatedObjectIDsResultType
                batchUpdateRequest.propertiesToUpdate = ["OBJECT_KEY": "NEWVALUE"]
                var batchUpdateRequestError: NSError?
                context.executeRequest(batchUpdateRequest, error:&batchUpdateRequestError)
                if let error = batchUpdateRequestError {println("error")}
    

    good luck

提交回复
热议问题