Xcode Swift应用程序部署到iPhone损失CoreData iPhone重新启动后 [英] Xcode Swift application deployed to iphone losses CoreData after iPhone reboot
问题描述
我的简单Swift应用程序在CoreData中使用SQLite数据库来存储表视图数据。我通过模拟器将应用程序部署到我的iPhone。重新启动iPhone后,持久数据不再存在....但应用程序启动。我必须怎样做才能保持数据的持久性?
IOS9.2.1& Swift 2.0
My simple Swift application uses an SQLite DB in CoreData for table view data. I deployed the app to my iPhone via the simulator. After a reboot of the iPhone the persistent data was no longer present....but the application launches. What must I do to keep the data persistent? IOS9.2.1 & Swift 2.0
推荐答案
CoreData有趣的一点是它不是数据库。
One thing that's interesting about CoreData is that it isn't a database. It's a wrapper around a data store, in your case SQLite.
如果你不告诉CoreData保存它的内容,它将永远不会将更改写入数据存储
If you don't tell CoreData to save it's contents, it will never write the changes to disk.
在您的NSManagedObjectContext上调用 save
:)
Calling save
on your NSManagedObjectContext will do the trick. :)
还有其他原因,它不会持久,但我会先检查这一点。
There are other reasons that it wouldn't persist, but I would check this first.
这篇关于Xcode Swift应用程序部署到iPhone损失CoreData iPhone重新启动后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!