Member-only story
App settings in the Native Settings
1 min readDec 10, 2024
Steps to Add App Settings to Native Settings
- Create a Settings Bundle
- Add a Settings.bundle to your project:
- In Xcode, right-click your project in the Project Navigator.
- Select New File > Resource > Settings Bundle.
- Name it
Settings.bundle
. - Modify
Root.plist
- The
Root.plist
file inside theSettings.bundle
defines the structure of your settings.
Example setup:
func appSettingsForVersionAndResetCache() {
let checkResetCacheON = UserDefaults.standard.value(forKey: "reset_cache") as? Bool
if checkResetCacheON ?? false {
resetCache()
// Remove the "reset_cache" value from UserDefaults after reset
UserDefaults.standard.removeObject(forKey: "reset_cache")
} else { return }
// Set the app version in UserDefaults
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
var appVersion = version
#if DEBUG
appVersion += " (\(build))"
#endif
UserDefaults.standard.set(appVersion, forKey: "app_version")
}
}
// Function to handle cache reset
func resetCache() {
self.clearUserDefaults()
self.showRelaunchAlert()
}
In simple
Create a simple diagram or mind map showing the steps:
- Step 1: Create
Settings.bundle
. - Step 2: Edit
Root.plist
. - Step 3: Access settings with
UserDefaults
. - Step 4: Test in the Settings app.