jem*_*lia 0 core-data ios swift
我正在尝试添加textfield.text到我的 CoreData 中,我是 coredata 的新手,因此我在 google 上搜索并复制了如何执行此操作,但 xCode 返回错误: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")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1218 次 |
| 最近记录: |