Introduction
Welcome to the documentation page for YTKKeyValueStore_Swift. This library provides a convenient and lightweight wrapper around Key-Value Store, designed to simplify data management in Swift applications. With YTKKeyValueStore_Swift, you can easily store, retrieve, update, and delete data in a Key-Value format.
Installation Guide
To install YTKKeyValueStore_Swift in your project, follow these steps:
- Open your Xcode project and navigate to the root directory.
-
Open the Podfile and add the following line:
pod 'YTKKeyValueStore_Swift'
-
Save the file and run the following command in the terminal:
$ pod install
- Wait for the Cocoapods installation process to finish.
- Once completed, open your project’s workspace file (with .xcworkspace extension).
-
Import the YTKKeyValueStore_Swift library into your Swift file:
import YTKKeyValueStore_Swift
- Now you are ready to start using YTKKeyValueStore_Swift in your project!
Usage Guide
Initialization
Before using YTKKeyValueStore_Swift, you need to initialize an instance of the library. Use the following code snippet to initialize:
// Create an instance of YTKKeyValueStore
let store = YTKKeyValueStore(dbName: "MyKeyValueStore.db")
In the above code, replace “MyKeyValueStore.db” with the desired name for your Key-Value store database.
Data Operations
Insert
To insert data into the store, use the put method. The method takes a key-value pair as parameters:
// Insert an object with a key
store.put(object: myObject, forKey: "MyKey")
Retrieve
To retrieve data from the store, use the get method with the specified key:
// Retrieve an object with a key
let retrievedObject = store.get(forKey: "MyKey")
Update
To update data in the store, use the put method with an existing key. The method will replace the existing data with the specified object:
// Update an object with a key
store.put(object: updatedObject, forKey: "MyKey")
Delete
To delete data from the store, use the delete method with the specified key:
// Delete an object with a key
store.delete(forKey: "MyKey")
Count
To get the count of objects stored in the Key-Value store, use the count method:
// Get the count of objects stored
let count = store.count()
Conclusion
By following this documentation, you should now have a good understanding of how to use YTKKeyValueStore_Swift to manage data in your Swift application. With its simple and efficient Key-Value storage operations, you can easily store and manipulate data to suit your needs.