Core data database deletes itself

Go To StackoverFlow.com

0

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!

2012-04-04 04:36
by tomidelucca
Need more info...especially about how you are creating your persistent store coordinator (and the directory you are saving it in - borrrden 2012-04-04 04:40
Im using an UIManagedDocument, i followed an iTunes U course from Standford University, CS193P. The code worked well in my other apps, but in this one it randomly deletes my whole database - tomidelucca 2012-04-04 05:13
Sounds like you have some initialization routine that is being triggered to create a new document or delete the underlying store file - ImHuntingWabbits 2012-04-04 05:20
Where should i open/create my core data database - tomidelucca 2012-04-04 05:26
You should use the template code provided by Apple. Did you do that or did you implement your own - sosborn 2012-04-04 06:35
Post here the code where you open the database or any other way interact with it (maybe the saving/loading of the objects is not necessary - MrTJ 2012-04-04 07:43


0

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!");
}];}
2013-05-27 07:30
by acecapades
Ads