Introduction
Welcome to the EasyStash documentation! EasyStash is a powerful library that simplifies persistent data storage in your iOS applications. With EasyStash, you can effortlessly save and retrieve data in just a few lines of code.
Features
- Simple and intuitive API
- Supports storing data in key-value format
- Automatic serialization and deserialization of objects
- Easy retrieval and deletion of stored data
- Efficient storage management
- Compatibility with various data types
Installation
- Open Terminal
- Navigate to your project directory
- Run the following command to install EasyStash via CocoaPods:
pod 'EasyStash'
- Wait for the installation to complete
- Now, you can import EasyStash in your project using:
import EasyStash
Getting Started
To get started with EasyStash, follow the steps below:
Step 1: Initialization
Firstly, initialize an instance of EasyStash by calling the EasyStash.initialize()
method in your AppDelegate’s application(_:didFinishLaunchingWithOptions:)
method. This is necessary to set up the required storage configuration.
// Inside AppDelegate.swift
import EasyStash
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
EasyStash.initialize()
return true
}
Step 2: Storing Data
Once EasyStash is initialized, you can store data using the EasyStash.store(_:forKey:)
method. This method allows you to save data in key-value format. The data can be of any Encodable type, including custom objects.
// Store a string value
EasyStash.store("Hello, EasyStash!", forKey: "greeting")
// Store a custom object
struct User: Codable {
let name: String
let age: Int
}
let user = User(name: "John Doe", age: 25)
EasyStash.store(user, forKey: "currentUser")
Step 3: Retrieving Data
To retrieve data from EasyStash, use the EasyStash.retrieve(forKey:)
method. This method returns an optional value, so make sure to handle the potential absence of data.
// Retrieve a string value
if let greeting = EasyStash.retrieve(forKey: "greeting") as? String {
print(greeting)
}
// Retrieve a custom object
if let user = EasyStash.retrieve(forKey: "currentUser") as? User {
print(user.name)
print(user.age)
}
Step 4: Deleting Data
To delete data from EasyStash, you can use the EasyStash.delete(forKey:)
method. Specify the key corresponding to the data you want to delete.
// Delete a stored value
EasyStash.delete(forKey: "greeting")
Conclusion
Congratulations! You have successfully learned the basics of using EasyStash for persistent data storage in your iOS applications. Feel free to explore the additional functionalities and customization options provided by EasyStash. For detailed information, you can refer to the official EasyStash documentation.