8

I'm working on a Mac OS X app that was developed for Mountain Lion. The app performs some setup tasks the first time it runs. It then sets a flag in [NSUserDefaults standardUserDefaults]; on subsequent runs the app checks to see if that flag is set, and does not perform these first time setup tasks if it is set.

On Mountain Lion, I was able to delete the ~/Library/Preferences/bundleid.plist file to wipe out everything stored in NSUserDefaults by the app. However, on more recent versions of Mac OS X, when the app runs it's not even creating that file. I verified that it is saving data successfully to NSUserDefaults by inspecting values coming back from [[NSUserDefaults standardUserDefaults] objectForKey:@"foo"] in the debugger.

Can anyone point me in the right direction regarding how to delete my app's settings that are stored in NSUserDefaults?

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
Greg
  • 33,450
  • 15
  • 93
  • 100
  • 1
    Mavericks is still under NDA, so I doubt anybody can answer your question directly. That said, have you tried using fs_usage (a tool available in all versions of OS X) to see where the app is trying to save the plist? – iccir Oct 07 '13 at 21:14
  • Whoops, my bad - I removed references to Mavericks. – Greg Oct 07 '13 at 21:22
  • I figure this is safe, though: https://devforums.apple.com/message/894120 – Nicholas Riley Oct 07 '13 at 21:32
  • @Greg: Your question is still about Mavericks. The codename isn't under NDA (Apple announced that publicly), but where it does or does not store preference files is, until Mavericks comes out. – Peter Hosey Oct 08 '13 at 00:29
  • @PeterHosey: I'm doing my best to make this question version neutral. FYI, the data DOES eventually get written to a file under ~/Library/Preferences; it just doesn't happen as quickly. – Greg Oct 08 '13 at 01:14

1 Answers1

18

Mavericks isn't released yet, so I'm ignoring that part of the question. You should be asking on the developer forums if you want a Mavericks-specific answer.

Regardless of OS X version, the right way to delete a defaults domain is with defaults delete bundleid or its programmatic equivalent. ~/Library/Preferences is an implementation detail. The plists contained therein do not always contain the latest information. Prior to Mountain Lion, defaults changes are buffered in individual applications until they synchronize; in Mountain Lion and later, they are maintained in memory in cfprefsd processes and flushed to disk lazily.

See the Core Foundation release notes for 10.8 for more information.

2016 update: A current guide to the state of NSUserDefaults is here.

Community
  • 1
  • 1
Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124