提问人:John Zalubski 提问时间:12/7/2022 更新时间:12/7/2022 访问量:98
如何将 NULL 值保存到核心数据
how to save a null value to core data
问:
我正在使用辅助方法尝试将 null 值保存到核心数据。
@objc func newB() {
CoredataHandler.saveObject(username: null, password : null, tf: null)
}
class CoredataHandler : NSManagedObject {
class func saveObject(username: String,password: String,tf: Bool) -> Bool{
let context = getContext()
let entity = NSEntityDescription.entity(forEntityName: "User", in: context)
let managedObject = NSManagedObject(entity: entity!, insertInto: context)
managedObject.setValue(username, forKey: "username")
managedObject.setValue(password, forKey: "password")
managedObject.setValue(tf, forKey: "tf")
do {
try context.save()
return true
} catch{
return false
}
}
我试图将值保存为 coredataHandler.saveObject(username: null, password : null, tf: null),但这不适合试图传递到类 func saveObject 的参数中的内容。
答: 暂无答案
评论
nil
null