### Description
The RHKeyValueStore is a helpful library that provides a key-value data store for efficient and easy data management in iOS apps. It simplifies the process of saving, retrieving, and removing data using a simple and straightforward interface.
### Installation
To include the RHKeyValueStore library in your iOS project, you can choose from the following methods:
#### Cocoapods
Add the following line to your Podfile:
“`ruby
pod ‘RHKeyValueStore’
“`
#### Carthage
Add the following line to your Cartfile:
“`ruby
github “robertherdzik/RHKeyValueStore”
“`
Afterwards, run `carthage update` and include the framework in your project.
#### Manual Installation
Alternatively, you can manually add the RHKeyValueStore framework to your project. Simply drag and drop the framework files into your Xcode project. Make sure to select the option to “Copy items if needed” and add the framework to your app’s target.
### Usage
Using RHKeyValueStore is straightforward. First, import the framework:
“`swift
import RHKeyValueStore
“`
#### Initializing the Store
Create an instance of `RHKeyValueStore` by calling its initializer:
“`swift
let store = RHKeyValueStore()
“`
#### Saving Data
To save data to the key-value store, use the `saveObject(_:forKey:)` method:
“`swift
store.saveObject(“John Doe”, forKey: “username”)
“`
#### Retrieving Data
To retrieve data from the key-value store, use the `object(forKey:)` method:
“`swift
if let username = store.object(forKey: “username”) as? String {
// Use the retrieved value
}
“`
#### Removing Data
To remove data from the key-value store, use the `removeObject(forKey:)` method:
“`swift
store.removeObject(forKey: “username”)
“`
### Additional Features
The RHKeyValueStore library also provides additional features for more advanced data management:
#### Managing Expiration Dates
You can save objects with an expiration date using the `saveObject(_:forKey:expiration:)` method. This allows you to automatically remove expired objects from the store:
“`swift
let expirationDate = Date() + 3600 // 1 hour from now
store.saveObject(“John Doe”, forKey: “username”, expiration: expirationDate)
“`
#### Clearing the Store
To remove all objects from the key-value store, use the `clearAll()` method:
“`swift
store.clearAll()
“`
#### Checking Object Existence
You can check if an object exists in the key-value store by using the `containsObject(forKey:)` method:
“`swift
if store.containsObject(forKey: “username”) {
// Object exists
} else {
// Object doesn’t exist
}
“`
### Conclusion
With RHKeyValueStore, managing data in your iOS app becomes easier and more efficient. It provides a simple and convenient interface for saving, retrieving, and removing key-value pairs. Incorporate RHKeyValueStore into your project to streamline your data management tasks.