我的代码是在coredata数据库中保存数据。请告诉我更好的方法是什么。
gradle.properties
答案 0 :(得分:0)
There is no reason to use a persistentContainer is you are not ios 10 and above only. Just create a stack that works and use it. PersistentContainer helps in not having to create a core data stack, but if you are creating one anyway there is really no point to using it.
答案 1 :(得分:0)
你可以使用
let context =(UIApplication.shared.delegate as!AppDelegate).persistentContainer.viewContext
让newcontact = NSEntityDescription.insertNewObject(forEntityName:“Employee”,into:context)as NSManagedObject
newcontact.setValue(txtempid.text, forKey: "emp_id");
newcontact.setValue(txtempname.text, forKey: "emp_name");
newcontact.setValue(txtempadd.text, forKey: "emp_add");
do
{
try context.save()
}
catch
{
}