gpt4 book ai didi

ios - 使用 NSBatchUpdateRequest 将核心数据属性设置为 nil

转载 作者:搜寻专家 更新时间:2023-10-30 22:17:48 25 4
gpt4 key购买 nike

是否可以使用 NSBatchUpdateRequest 将属性设置为 nil?将 NSNull() 传递给 propertiesToUpdate 无效:

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)")
}

我没有收到任何错误,但它没有清除日期。

我也试过将它设置为 NSExpression(forConstantValue: NSNull()),但这也不起作用(forConstantValue 参数不接受可选值,所以我不能传递它nil。)。

最佳答案

当前的 API 允许将 nil 作为常量值传递。

unlockRequest.propertiesToUpdate = ["lockDate": NSExpression(forConstantValue: nil)]

关于ios - 使用 NSBatchUpdateRequest 将核心数据属性设置为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com