Giter Club home page Giter Club logo

genericlocalpersistence's Introduction

GenericLocalPersistence

GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like,

  • UserDefaults
  • PList
  • Keychain

Installation

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'

Usage of UserDefault

import GenericLocalPersistence

Set & Get value from User Default

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

private let managerPlist = plistManager(named: "userDetails")
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

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

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)
}

NOTE

Replace "com.appBundleID" with your project bundleID for KeyChain integration
Define the dataType in which you want to fetch the value and thats 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

MIT

genericlocalpersistence's People

Contributors

ashishpatelmi avatar riddhi-mi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.