Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- //Little more type safe version of storage
- class DeviceStorage {
- //Bool functions
- static func getBool(forKey key: String) -> Bool? {
- if UserDefaults.standard.object(forKey: key) == nil {
- // Если такого ключа в базе нет - возрващаем nil ! а не false.
- return nil
- }
- return UserDefaults.standard.bool(forKey: key)
- }
- static func setBool(_ value: Bool, forKey key: String) {
- UserDefaults.standard.set(value, forKey: key)
- }
- //String functions
- static func getString(forKey key: String) -> String? {
- return UserDefaults.standard.string(forKey: key)
- }
- static func setString(_ value: String, forKey key: String) {
- return UserDefaults.standard.set(value, forKey: key)
- }
- static func delete(key: String) {
- UserDefaults.standard.removeObject(forKey: key)
- }
- }
Add Comment
Please, Sign In to add comment