Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Core Data attribute to nil with NSBatchUpdateRequest

Is it possible to set an attribute to nil using NSBatchUpdateRequest? Passing NSNull() to propertiesToUpdate isn't working:

let unlockRequest = NSBatchUpdateRequest(entityName: "MyEntity")
unlockRequest.predicate = NSPredicate(format: "self in %@", myObjectIDs)
unlockRequest.propertiesToUpdate = ["lockDate": NSNull()]
var error: NSError?
myContext.executeRequest(unlockRequest, error: &error)
if let error = error {
    log.error("Failed to unlock: \(error)")
}

I don't get any errors, but it doesn't clear the date.

I've also tried setting it to NSExpression(forConstantValue: NSNull()), but that doesn't work either (forConstantValue argument does not accept an optional value, so I can't pass it nil.).

like image 446
Sencha Avatar asked Sep 03 '15 18:09

Sencha


1 Answers

Current API allows to pass nil as a constant value.

unlockRequest.propertiesToUpdate = ["lockDate": NSExpression(forConstantValue: nil)]
like image 62
Shmidt Avatar answered Oct 16 '22 13:10

Shmidt