GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like,
- UserDefaults
- PList
- Keychain
Read more from MEDIUM
From CocoaPods First, add the following line to your Podfile
pod install 'GenericLocalPersistence', '~> 0.0.1’
pod 'GenericLocalPersistence', :git => 'https://github.com/Riddhi-mi/GenericLocalPersistence.git'
import GenericLocalPersistence
DefaultManager().saveValueInDefault(value: "TestValue", using: "TestKey")
let valueFetch:String = DefaultManager().getValue("TestKey") ?? ""
import GenericLocalPersistence
Replace "userDetails" with custom name for creating plist file to store data
private let managerPlist = plistManager(named: "userDetails")
managerPlist?.saveDatatoPlist(value: "TestString Value", using: "TestKey")
let stringValue :String = managerPlist?.getDictionary(key: "TestKey") ?? ""
import GenericLocalPersistence
let passWordString = textPassword?.text?.data(using: .utf8, allowLossyConversion: false) ?? Data()
let passwordStatus = KeyChainManager()?.save(key: "com.appBundleID.password", data: passWordString)
//Retrive data
if let receivedData = KeyChainManager()?.load(key: "com.appBundleID.password") {
let data = String(decoding: receivedData, as: UTF8.self)
print("result: ", data)
}
let userNameString = textName?.text?.data(using: .utf8, allowLossyConversion: false) ?? Data()
let emailStatus = KeyChainManager()?.save(key: "com.appBundleID.email", data: userNameString)
//Retrive data
if let data = KeyChainManager()?.load(key: "com.appBundleID.email") {
let data = String(decoding: data, as: UTF8.self)
print("result: ", data)
}
Replace "com.appBundleID" with your project bundleID for KeyChain integration
Define the dataType in which you want to fetch the value and that’s the way you can get the stored value.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
GenericLocalPersistence is MIT-licensed.