KeeyboardKeda
Posted on October 17, 2021
In this project I learned about UserDefaults, NSCoding and reviewed the Codable protocol. UserDefaults lets you store program settings, user settings and runs as soon as the app loads.
Key Takeaways:
- When using the nil coalescing operator you want to see if the code on the left side of the operator "??" has a value and if not then use the value on the right side of the operator. Example,
let array = defaults.object(forkey: "SavedArray") as? [String] ?? String
If there is a value for the key SavedArray then set it as the value for the constant array, if not then set it to be a new string array.
NSKeyedArchiver.archivedData(withRootOgbject:, requiringSecureCoding:) encodes(writes) an object graph with the given root object into a data representation, optionally requiring secure coding. An object graph is your object, plus other objects it refers to and so on.
NSKeyedUnarchiver.unarchivTopLevelObjectWithData() decodes(reads) archived object graph and returns the object root.
4.Using "if let" and "try?" helps to save data only when converting into to a Data object was successful.
Posted on October 17, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.