Adding settings to your iOS app

  • Display preferences inside the app.
  • Use a Settings bundle to manage preferences from the Settings app.
Fig 1. Types of controls supported by the Settings app

Adding the Settings Bundle

To add a Settings bundle to your Xcode project:

  1. Choose File > New > New File.
  2. Under iOS, choose Resource, and then select the Settings Bundle template.
  3. Name the file Settings.bundle.
func applicationDidBecomeActive(_ application: UIApplication) {SettingsBundleHelper.checkAndExecuteSettings()SettingsBundleHelper.setVersionAndBuildNumber()}

Updating Defaults with Observers

The above method has a drawback that we have to call the code every time when the app launches. Alternatively you can set an observer for UserDefaults using NSUserDefaultsDidChangeNotification which is now UserDefaults.didChangeNotification.

deinit { //Not needed for iOS9 and above. ARC deals with the observer in higher versions.NotificationCenter.default.removeObserver(self)}

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhimuralidharan

Abhimuralidharan

iOS and tvOS developer, dreamer, photographer 🤨