StoredInUserDefaults
is a utility for UserDefaults
with strong types and easiness.
Please use the Swift Package Manager
.
dependencies: [
.package(url: "https://github.com/moriturus/StoredInUserDefaults.git", .upToNextMajor(from: "1.0.0"))
]
import StoredInUserDefaults
struct AppSetting {
// Use as the property wrapper.
// You should specify a key which is used in `UserDefaults`.
@StoredInUserDefaults(key: "com.example.my-app.isAwesome")
var isAwesome: Bool
}
var setting = AppSetting()
print(setting.isAwesome) // prints `false` which means the default value is `false`.
setting.isAwesome = true
UserDefaults.standard.bool(forKey: "com.example.my-app.isAwesome") == setting.isAwesome // `true`
This software is released under the MIT License.
See LICENSE file for details.