I'm trying to add textfield.text
into my CoreData, I'm new to coredata therefore I googled and copied how to do it, but xCode returns an error: Cannot find 'NSEntityDescription' in scope
and Cannot find 'NSManagedObject' in scope
is there any easy solution to fix this ?
@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")
}
CodePudding user response:
You need to add
import CoreData