Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BadWolf13

macrumors 6502
Original poster
Dec 17, 2009
271
0
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?
 
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.
 
Wow, adding a BOOL is a really simple solution. I guess I really missed the forest for the trees on that one. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.