3

New to OS X development and have tried removing ~/Library/Developer/Xcode/DerivedData from my system, Product>Clean but still wouldn't wipe the data. I know its much simpler in iOS simulator. Any advise on removing OS X app data completely so that it runs like as if its the first time?

Obj-Swift
  • 2,802
  • 3
  • 29
  • 50

2 Answers2

2

Unlike iOS apps, macOS apps don't delete all of their data when uninstalled.

Assuming the data you are referring to is stored in the UserDefaults, this is the solution I found to test the app first launch.

  1. Quit Xcode
  2. Remove the DerivedData folder
  3. Delete the UserDefaults plist file. Depending on your app's configuration it will be in one of these locations (more info in this answer):

Sandboxed apps:

  • ~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
  • ~/Library/Containers/com.example.myapp/Data/Library/SyncedPreferences/com.example.myapp.plist

Non sandboxed apps:

  • ~/Libraryf/Preferences/com.example.myapp.plist
  • ~/Library/SyncedPreferences/com.example.myapp.plist
  1. Relaunch the app from Xcode

If the only thing you need to test is a flow based on a "first launch flag" (a Bool in the UserDefaults that is set to true after first launch), you can reset that one along with this command:

defaults write com.example.myapp "settingName" "0"

You'll still have to quit Xcode, delete the DerivedData, and re-open Xcode for the change to take place.

Note that sometimes this doesn't work on the first try. I'm not sure why but I'm guessing Xcode does some state tracking inside that gets in the way. In my experiments, I had to restart Xcode a few times before getting it to read the updated defaults.

mokagio
  • 16,391
  • 3
  • 51
  • 58
  • 1
    I wish the whole quitting and `DerivedData` deletion wasn't required. I someone knows a way to avoid having to do that, please let me know. – mokagio Nov 16 '20 at 23:29
-5

Oh just open up the Simulator and click (and hold) on the app icon. Then it'll shake and you click the 'x' in the corner to delete the app and its data.

Choppin Broccoli
  • 3,048
  • 2
  • 21
  • 28