How To Use List Of Objects With User Defaults iOS & Swift 4

Next Story

How To Customize UITabBar Icon Highlight Color iOS Swift 5

Ever wanted to store a list of objects into user defaults for reference later?

Lets check out the below code to do just that.


// to retrieve arrays from user defaults
UserDefaults.standard.array(forKey: "yourArrayKey")

// to store arrays of objects into user defaults
UserDefaults.standard.set(arrayToStore, forKey: "yourArrayKey")

// to delete the object from your user defaults
UserDefaults.standard.removeObject(forKey: "yourArrayKey")

Let me know if you have any questions…

User defaults is a simple way to store a small amount data for your iOS application and it is great to have a good understanding of how it works 🙂

https://www.googletagmanager.com/gtag/js?id=UA-63695651-4