Auto delete App Preference file upon closing App?

Discussion in 'Mac Programming' started by Jack Flash, Aug 14, 2007.

  1. macrumors 65816

    Joined:
    May 8, 2007
    #1
    Is there a way to have OS X auto-delete a .plist file when an Application is closed?
     
  2. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #2
    I'm not sure why you'd want to do this, but it can be done easily enough.

    - If you haven't already done so, you need an object acting as the application's delegate i.e.
    Code:
    [[NSApplication sharedApplication] setDelegate:self];
    - Then you need to implement applicationWillTerminate, and put your code in there.

    - You could hard code the path of the preference file by looking in ~/Library/Preferences; but the correct way might be to use NSUserDefaults method removePersistentDomainForName (I haven't tried it, so I'm not sure if that deletes the preference file, but I expect it would).
     
  3. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    You could use the delegate of [NSApplication sharedApplication] as described above to store the revelent information rather than using preferences, and that is lost when the application closes ;).

    PS [NSApplication sharedApplication] can be accessed with the constant NSApp.
     

Share This Page