Member-only story

App settings in the Native Settings

Steps to Add App Settings to Native Settings

  1. Create a Settings Bundle
  • Add a Settings.bundle to your project:
  1. In Xcode, right-click your project in the Project Navigator.
  2. Select New File > Resource > Settings Bundle.
  3. Name it Settings.bundle.
  4. Modify Root.plist
  • The Root.plist file inside the Settings.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.

--

--

No responses yet