Welcome to the documentation for CCLDefaults, a lightweight library for managing UserDefaults in iOS applications.
Installation
To integrate CCLDefaults into your project, simply add the following line to your Podfile:
// Podfile
pod ‘CCLDefaults’
Then run pod install
to install the dependency.
Usage
1. Importing the Library
Before using CCLDefaults in your code, import the CCLDefaults module:
import CCLDefaults
2. Saving and Retrieving Values
You can store and retrieve values using the UserDefaults
class provided by CCLDefaults. Simply call the appropriate methods to set or get the values:
// Setting a value
UserDefaults.setValue(value, forKey: “key”)
// Getting a value
let value = UserDefaults.getValue(forKey: “key”)
3. Observing Value Changes
CCLDefaults allows you to observe changes to UserDefaults values using the NotificationCenter
API. Simply add an observer for the desired key:
NotificationCenter.addDefaultValueObserver(forKey: “key”) { newValue in
// Handle the updated value
}
4. Removing Observers
To remove an observer, call the removeDefaultValueObserver(forKey:)
method with the corresponding key:
NotificationCenter.removeDefaultValueObserver(forKey: “key”)
Conclusion
CCLDefaults provides a straightforward way to manage UserDefaults in your iOS applications. Whether you need to save and retrieve values or observe changes, CCLDefaults has you covered. Give it a try and improve the efficiency of your UserDefaults usage!