PDA

View Full Version : Terminating An Application Without ApplicationShouldTerminate




BadWolf13
Jun 29, 2012, 01:38 PM
I'm working on a core data app, which, like most core data apps, has all the code for saving the database within ApplicationShouldTerminate. However, in one case, I want the program to shut down without saving the database.

I doubt that there's any way to completely bypass the ApplicationShouldTerminate method, so is there a notification or something that I can set in the call to terminate that I could query in that method to quit before anything gets saved?



GorillaPaws
Jun 29, 2012, 01:57 PM
Why not break out the core data saving logic into it's own private method call? Add a BOOL property to your app delegate class called shouldSaveOnQuit with a default value of YES. In your ApplicationShouldTerminate delegate call, check the value of this bool and call your private core data saving method if yes, else don't. When your code hits the parts where you want to disable the saving on quit behavior, set the App Delegate's shouldSaveOnQuit to NO.

BadWolf13
Jun 29, 2012, 02:05 PM
Wow, adding a BOOL is a really simple solution. I guess I really missed the forest for the trees on that one. Thanks.