Saving small data when the App is not running (session or other state variables)
let defaults = UserDefaults.standardWriting data
let valueToBeSaved = "THIS_IS_THE_API_KEY"
defaults.set(valueToBeSaved, forKey: "apiKey")Reading data
let apiKeySaved = defaults.object(forKey: "apiKey") as! String?
if let apiKey = apiKeySaved{
//MARK: tasks if there is a key saved
print("The Saved API Key: \(apiKey)")
}else{
//MARK: tasks if there is no key saved
print("No API Key saved at the moment!")
}Last updated