본문 바로가기
# 애플 [Apple]/iOS

[iOS] UserDefaults

by cy_mos 2019. 8. 1.
반응형
How to save user settings using UserDefaults – Swift 5

An interface to the user’s defaults database, where you store key-value pairs persistently across launches of your app.

 

  • integer (forKey:)
  • bool (forKey:)
  • float (forKey:)
  • double (forKey:)
  • object (forKey:)

📄 UserDefaultes Swift Source Code

let defaults = UserDefaults.standard

// SAVE
defaults.set(25, forKey: "Age")
defaults.set(true, forKey: "UseTouchID")
defaults.set(CGFloat.pi, forKey: "Pi")

// LOAD
let age = defaults.integer(forKey: "Age")
let useTouchID = defaults.bool(forKey: "UseTouchID")
let pi = defaults.double(forKey: "Pi")

🚀 REFERENCE

 

How to save user settings using UserDefaults - free Swift 5.0 example code and tips

Was this page useful? Let me know! 1 2 3 4 5

www.hackingwithswift.com

 

UserDefaults - Foundation | Apple Developer Documentation

Posted when ubiquitous defaults finish downloading data, either the first time a device is connected to an iCloud account or when a user switches their primary iCloud account.

developer.apple.com

반응형

댓글