Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mindinventory/genericlocalpersistence
GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like UserDefaults, PList, Keychain.
https://github.com/mindinventory/genericlocalpersistence
ios keychain localstorage plist plist-files savedata storage swift userdefaults
Last synced: 3 months ago
JSON representation
GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like UserDefaults, PList, Keychain.
- Host: GitHub
- URL: https://github.com/mindinventory/genericlocalpersistence
- Owner: Mindinventory
- License: mit
- Created: 2021-05-25T10:18:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-02T09:41:36.000Z (over 3 years ago)
- Last Synced: 2024-10-20T11:21:36.461Z (4 months ago)
- Topics: ios, keychain, localstorage, plist, plist-files, savedata, storage, swift, userdefaults
- Language: Swift
- Homepage: https://www.mindinventory.com/iphone-application-development.php
- Size: 28.3 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GenericLocalPersistence
GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like,
* **UserDefaults**
* **PList**
* **Keychain**Read more from [MEDIUM](https://medium.com/mindful-engineering/generic-local-persistence-8b4cfa5dbf7d)
## Installation
From CocoaPods
First, add the following line to your Podfile```bash
pod install 'GenericLocalPersistence', '~> 0.0.1’pod 'GenericLocalPersistence', :git => 'https://github.com/Riddhi-mi/GenericLocalPersistence.git'
```# Usage of UserDefault
import GenericLocalPersistence
### Set & Get value from User Default
```python
DefaultManager().saveValueInDefault(value: "TestValue", using: "TestKey")
let valueFetch:String = DefaultManager().getValue("TestKey") ?? ""
```# Usage of Plist
import GenericLocalPersistence
### Set & Get value from plist file
Replace "userDetails" with custom name for creating plist file to store data```python
private let managerPlist = plistManager(named: "userDetails")
``````python
managerPlist?.saveDatatoPlist(value: "TestString Value", using: "TestKey")
let stringValue :String = managerPlist?.getDictionary(key: "TestKey") ?? ""
```## Usage of KeyChain
import GenericLocalPersistence### Set & Get value from KeyChain file
#### Store password value
```python
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)
}
```#### Store username value
```pythonlet 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)
}
```## NOTE
```python
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.
```## Contributing
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.
## License
GenericLocalPersistence is [MIT-licensed](/LICENSE).