Closed metasmile closed 6 years ago
Hi @metasmile,
Thank you for contributing 👍 Could you explain what an AutoProperty is? And what's it for?
Thanks
edit: scratch that question, there a README.md update in there 🤔
Hi @nmdias There's no special reason. Just for shorthand senario in devs point of view.
extension Defaults: DefaultsAutoProperty {
public var autoStringProperty: String? { set{ set(newValue) } get{ return get() } }
}
So autoStringProperty will be guaranteed.
And naturally, we can use them with the following style
Defaults.shared.autoStringProperty = "new value will persist"
Rendered readme is here : https://github.com/metasmile/DefaultsKit
Just want to chime in and say I'd also like a way to provide a default value/get a non-optional from Defaults().get()
. I've only glanced at DefaultsKit, but this does seem like a big change and a different API/usage (via extensions on Defaults
per the readme in this PR).
@rudedogg This is only a utility protocol/extension. Although I'm usefully using it in my project when I register and manage properties and default value/scheme safely, but yes, your opinion may be right. Anyway for reference, this is a way to define non-optional.
var nonOptionalProperty: Int {
set { set(newValue) }
get { return get(or: 5) } // 5 is default value if "nonOptionalProperty" is nil.
}
Please confirm and thanks for making your very useful DefaultsKit.