If you want UserDefaults to clear every time you install a new Debug build via Xcode, regardless of version or build number, you can inject a unique marker that changes on every build.
Go to:
Build SettingsβUser-Definedβ click+
Add:
Key: BUILD_ID
Value: ${CURRENT_PROJECT_VERSION}-${CURRENT_TIME}
Or just:
BUILD_ID = $(CURRENT_PROJECT_VERSION)-$(SOURCE_ROOT)
Then expose it to your code via Build Settings β Swift Compiler β Custom Flags:
Other Swift Flags: -D BUILD_ID="your-build-id-here"
But this is clunky.
Use a script to write a random UUID into Info.plist every time you build:
In your project:
Target β Build Phases β "+" β "New Run Script Phase"
Paste:
uuid=$(uuidgen)
defaults write "${SRCROOT}/Info" BuildUUID "$uuid"Or if you're managing Info.plist in Xcode directly:
/usr/libexec/PlistBuddy -c "Set :BuildUUID $(uuidgen)" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"