Im having trouble with my core data database. It randomly deletes itself. I've used my app for a week and everything worked perfectly, but today y opened the app and figured out that all the entries had been deleted (not the first time that happens). Im new to core data programming, but I understand iOS and Objective-C. I need to know where i should check in my code for bugs, is it the save function? Thanks!
You might want to check if you're explicitly calling the save function for the UIManagedDocument. For simplicity's sake, the Stanford CS193P demo project on this, if I'm not mistaken, relied on the automatic calling of the save function of UIManagedDocument. In some cases, the saving takes a while. And the app can be terminated even before this is done. This might explain the loss of your data.
Here's a sample code for saving your database:
- (void) saveDatabase{
[myDatabase saveToURL:myDatabase.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
if(success == YES) NSLog(@"Awesome, databse is saved! booooyah!");
}];}