There is a post by Paul Hudson where he explains how structs can be stored in UserDefaults.
He recommends converting the value to Data type first and then store it directly in UserDefaults.
Similarly for retreving, get the Data and decode it to get the desired type back
So to make it more convenient and Swifty, I have written the following extension
After adding above methods to UserDefaults one can easily store Codable types in UserDefaults with just one line of code