在范围内找不到 'NSEntityDescription' 和 'NSManagedObject'
Cannot find 'NSEntityDescription' and 'NSManagedObject' in scope
我正在尝试将 textfield.text
添加到我的 CoreData 中,我是 coredata 的新手,因此我用谷歌搜索并复制了操作方法,但是 xCode returns 出现错误: Cannot find 'NSEntityDescription' in scope
和 Cannot find 'NSManagedObject' in scope
有什么简单的解决方案可以解决这个问题吗?
@objc func textFieldDidChange(_ textField: UITextField) {
print(textField.text ?? "username581293491822")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Users", in: context)
let newUser = NSManagedObject(entity: entity!, insertInto: context)
newUser.setValue(textField.text ?? "username12312235234", forKey: "username")
}
您需要添加
import CoreData
我正在尝试将 textfield.text
添加到我的 CoreData 中,我是 coredata 的新手,因此我用谷歌搜索并复制了操作方法,但是 xCode returns 出现错误: Cannot find 'NSEntityDescription' in scope
和 Cannot find 'NSManagedObject' in scope
有什么简单的解决方案可以解决这个问题吗?
@objc func textFieldDidChange(_ textField: UITextField) {
print(textField.text ?? "username581293491822")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Users", in: context)
let newUser = NSManagedObject(entity: entity!, insertInto: context)
newUser.setValue(textField.text ?? "username12312235234", forKey: "username")
}
您需要添加
import CoreData