Created
February 17, 2017 05:07
-
-
Save npu3pak/04e14bf78cfba408699caffb2d25254a to your computer and use it in GitHub Desktop.
Хелпер для работы с настройками на Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class PreferencesStorage { | |
private static let keyStartBusStopId = "StartBusStopId" | |
var startBusStopId: Int64? | |
private static let keyEndBusStopId = "EndBusStopId" | |
var endBusStopId: Int64? | |
private init() {} | |
//Загрузка | |
static func load() -> PreferencesStorage { | |
let defaults = UserDefaults.standard | |
let storage = PreferencesStorage() | |
storage.startBusStopId = defaults.object(forKey: PreferencesStorage.keyStartBusStopId) as? Int64 | |
storage.endBusStopId = defaults.object(forKey: PreferencesStorage.keyEndBusStopId) as? Int64 | |
return storage | |
} | |
func save() { | |
let defaults = UserDefaults.standard | |
defaults.set(startBusStopId, forKey: PreferencesStorage.keyStartBusStopId) | |
defaults.set(endBusStopId, forKey: PreferencesStorage.keyEndBusStopId) | |
defaults.synchronize() | |
} | |
func clear() { | |
startBusStopId = nil | |
endBusStopId = nil | |
let defaults = UserDefaults.standard | |
defaults.removeObject(forKey: PreferencesStorage.keyStartBusStopId) | |
defaults.removeObject(forKey: PreferencesStorage.keyEndBusStopId) | |
defaults.synchronize() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment