Save array in UserDefaults Swift

Saving Array is pretty straightforward

let array = ["String1", "String2", "String3", "String4", "String5", "String6"]
let defaults = UserDefaults.standard
defaults.set(array, forKey: "Your_Meaningful_Key")

Ready array is also quite simple

let defaults = UserDefaults.standard
let stringArray = defaults.stringArray(forKey: "Your_Meaningful_Key") ?? [String]()

you can remove the array by usng

let defaults = UserDefaults.standard
defaults.removeObject(forKey:"Your_Meaningful_Key")

Cheers !!!

NEED A JOB? NEED TO HIRE? NEED HELP?

Join group of Software Professionals

iOS DEVELOPER’S DEN