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.).
Current API allows to pass nil as a constant value.
unlockRequest.propertiesToUpdate = ["lockDate": NSExpression(forConstantValue: nil)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With