CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2018 |
SPMSupports SPM | ✗ |
Maintained by Rafał Wójcik.
Magical User settings class for iOS
To start using WRUserSettings just subclass WRUserSettings
class and you are ready to go!!!
So every property you add to your subclass will be stored in NSUserDefaults. Default property is nil or filled by default system value for primitive types like NSInteger, BOOL, CGRect etc.
To simple usage you only need add properties to header file of subclass:
class MyUserSettings: WRUserSettings {
dynamic var shouldShowTutorial: Bool = true
dynamic var temperatureUnit: String = "C"
dynamic var notyficationOn: Bool = false
}
From now every time you set property is automatically save it in NSUserDefaults for you.
Your class is singleton so you should use +shared
method to get instance of it:
MyUserSettings.shared.shouldShowTutorial = false
Class will automatically save value false
to NSUserDefaults
To get value just get instance of class and property:
let shouldItReallyShowTutorial = MyUserSettings.shared.shouldShowTutorial
To set default values just use default assigment as above. We are storing defaults in instance.
If you want reset settings call anywhere method reset()
on your singleton. This method iterate through all saved settings and delete it from NSUserDefaults and assign to properties default values.
To print description of stored values simply print your singleton. It prints only stored values so it don’t show default values that you set.
- Refactored Swift 3.0 version
- Swift version
- Add -resetSettings
method
- Add simple tests
- Example now use pod instead of imported WRUserSettings
files.
- Added support for structures like: CGPoint
, CGRect
, CGSize
etc.
- Modify example to show CGPoint
usage.
- Basic stuff working
WRUserSettings requires either iOS 8.0 and above.
WRUserSettings is available under the MIT license. See the LICENSE file for more info.
WRUserSettings uses ARC.