我想添加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")
}
uj5u.com熱心網友回復:
你需要添加
import CoreData
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370548.html
