Guest User

Untitled

a guest
Apr 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /// A list of Keys used to persist data
  2. enum DefaultsKey: String {
  3. case game = "Game"
  4. }
  5. /// A type providing DAO services for `UserDefaults` persistence.
  6. protocol DefaultsServiceType {
  7. /// Read & decode a value for a given key from standard `UserDefaults`.
  8. ///
  9. /// - Parameter forKey: Defaults key to be read.
  10. /// - Returns: Decoded value if possible. `nil` if not present in standard defaults or if decoding threw an error.
  11. func read<T: Decodable>(forKey: DefaultsKey) -> T?
  12. /// Encode & write a value to a give key in standard `UserDefaults`.
  13. ///
  14. /// If encoding the given value failed, existing value -if any- will be erased.
  15. ///
  16. /// - Parameters:
  17. /// - value: Value to encode and write to defaults.
  18. /// - forKey: Defaults key to write to
  19. func write<T: Encodable>(_ value: T, forKey: DefaultsKey)
  20. /// Erase a value for a given key -if present- from standard `UserDefaults`.
  21. ///
  22. /// - Parameter key: Defaults key to erase.
  23. func erase(_ key: DefaultsKey)
  24. }
Add Comment
Please, Sign In to add comment