Life, Technology, and Meteorology

Removing preferences belonging to your app…

I was working on some code to uninstall an application, and was pleasantly surprised to find that Cocoa’s NSUserDefaults class will remove the application’s preferences file from ~/Library/Preferences if you remove all the keys:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *keys = [[defaults dictionaryRepresentation] allKeys];

int i, count = [keys count];
for (i = 0; i < count; i++) {
   [defaults removeObjectForKey:[keys objectAtIndex:i]];

[defaults synchronize];

It’s not often you find uninstall options for OS X applications, but it’s nice Apple’s engineers thought about this case and handle it appropriately.

1 Comment

  1. logtar

    Are you sure you were not looking at vista… just kidding. LOL

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022 *Coder Blog

Theme by Anders NorenUp ↑