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

Jack Flash

macrumors 65816
Original poster
May 8, 2007
1,160
7
Is there a way to have OS X auto-delete a .plist file when an Application is closed?
 
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).
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.