Xcode Swift application deployed to iphone losses CoreData after iPhone reboot

一笑奈何 提交于 2020-01-06 02:55:44

问题


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


回答1:


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.

If you don't tell CoreData to save it's contents, it will never write the changes to disk.

Calling save on your NSManagedObjectContext will do the trick. :)

There are other reasons that it wouldn't persist, but I would check this first.



来源:https://stackoverflow.com/questions/35853065/xcode-swift-application-deployed-to-iphone-losses-coredata-after-iphone-reboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!