UserDefaults in Swift

This post was originally posted at and reposted on Medium on 13th April 2022.

What is UserDefaults

How UserDefaults works

How to use UserDefaults

let defaults = UserDefaults.standard
+standardUserDefaults returns a global instance of NSUserDefaults configured to search the current application's search list.
open class var standard: UserDefaults { get }

Write data to UserDefaults

let defaults = UserDefaults.standard//String Value
defaults.set("Suneet Agrawal", forKey: "stringKey")
//Int Value
defaults.set(1, forKey: "integerKey")
//Double Value
defaults.set(30.0, forKey: "doubleKey")
//Array Value
defaults.set([1,2,3], forKey: "intArrayKey")

Please continue reading at



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