Terminating An Application Without ApplicationShouldTerminate

Discussion in 'Mac Programming' started by BadWolf13, Jun 29, 2012.

  1. macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    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?
     
  2. macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #2
    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.
     
  3. thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #3
    Wow, adding a BOOL is a really simple solution. I guess I really missed the forest for the trees on that one. Thanks.
     

Share This Page