Fix countdown if settings is at 0
Opened this issue · 1 comments
If the countdown start is set to 0, we get a countdown that never ends. It might also happen for other out of range values.
Fixed locally, but not yet pushed yet.
When Settings
is initialized, we make sure the countdown is changed to PicItSetting.defaultCountdownFrom
.
This works, but I don't like how we magically change the setting. There is a fallback error that informs the user that the default is changing, but that's a bad UX as this occurs anytime the App is installed.
A better approach is to somehow initialize the UserDefaults
settings with the correct default value. But I've not had success yet (probably doing something stupid).
Also, it might be better toead the defaults from the plist, rather than hoping the code and plist stay in sync. Like the example code below, that probably doesn't work out of the box.
private func registerDefaultsFromSettingsBundle()
{
let settingsUrl = Bundle.main.url(forResource: "Settings", withExtension: "bundle")!.appendingPathComponent("Root.plist")
let settingsPlist = NSDictionary(contentsOf:settingsUrl)!
let preferences = settingsPlist["PreferenceSpecifiers"] as! [NSDictionary]
var defaultsToRegister = Dictionary<String, Any>()
for preference in preferences {
guard let key = preference["Key"] as? String else {
NSLog("Key not found")
continue
}
defaultsToRegister[key] = preference["DefaultValue"]
}
UserDefaults.standard.register(defaults: defaultsToRegister)
}