Guest User

Untitled

a guest
Jun 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import Foundation
  2.  
  3. //Little more type safe version of storage
  4. class DeviceStorage {
  5.  
  6. //Bool functions
  7. static func getBool(forKey key: String) -> Bool? {
  8. if UserDefaults.standard.object(forKey: key) == nil {
  9. // Если такого ключа в базе нет - возрващаем nil ! а не false.
  10. return nil
  11. }
  12. return UserDefaults.standard.bool(forKey: key)
  13. }
  14.  
  15. static func setBool(_ value: Bool, forKey key: String) {
  16. UserDefaults.standard.set(value, forKey: key)
  17. }
  18.  
  19. //String functions
  20. static func getString(forKey key: String) -> String? {
  21. return UserDefaults.standard.string(forKey: key)
  22. }
  23.  
  24. static func setString(_ value: String, forKey key: String) {
  25. return UserDefaults.standard.set(value, forKey: key)
  26. }
  27.  
  28. static func delete(key: String) {
  29. UserDefaults.standard.removeObject(forKey: key)
  30. }
  31. }
Add Comment
Please, Sign In to add comment