问题
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