Swiftpack.co - Echobird/KeychainManager as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Echobird.
Echobird/KeychainManager 1.0.0
iOS Keychain manager written with dream to ease saving secure info.
⭐️ 3
🕓 3 years ago
.package(url: "https://github.com/Echobird/KeychainManager.git", from: "1.0.0")

KeychainManager

Swift Package Manager compatible License

This library allows you simply and fast deal with Keychain.

Usage

Add import KeychainManager to your source code.

Save values

Since the library uses Generic types, you can pass as a parameter any values that are signed under the Codable protocol.

Exemples:

All functions above return Bool value as a result.

  • String:
KeychainManager.save(value: "SuperSecretInfo", key: "SomeSecretKey")
  • Int:
KeychainManager.save(value: 2021, key: "Year")
  • Bool:
KeychainManager.save(value: true, key: "Status")
  • Custom Types:
class BearerResponse: Codable {
    var accesToken: String?
    var refreshToken: String?
}

let bearer = BearerResponse()
bearer.accesToken = "some-acces-token"
bearer.refreshToken = "some-refresh-token"

KeychainManager.save(value: bearer, key: "tokenData")
Use completions:
KeychainManager.save(value: "Info", key: "key") {
        // succes
} failure: status in 
       // failure
}

Get values

Library provides two types of get functions.

Examples:

In this case, you need to cast the type of the function result yourself.

let someText = KeychainManager.get(forKey: "SomeSecretKey") as? String

or

KeychainManager.get(forKey: "SomeSecretKey") { (obj) in
       // succes, type of obj == Any?
} failure: {
       // failure 
}

And the second function accepts the type of object in parameters.

let someInt = KeychainManager.get(forKey: "Year", asType: Int.self) // return Int?

or

KeychainManager.get(forKey: "Year ", asType: Int.self) { (obj) in
       // succes , type of obj == Int?
} failure: {
       // failure
}

Update values

Returns Bool as result.

KeychainManager.update(value: "2077", forKey: "Year")

or

KeychainManager.update(value: "2077", forKey: "Year") {
        // succes
} failure: { status in
       // failure
}

Remove values

KeychainManager.erase(key: "Year")

or

KeychainManager.erase(key: "Year") {
       // succes
 } failure: { status in
      // failure
 }
To remove all Keychain info use:
KeychainManager.eraseAll()

Installation

Swift Package Manager

You can use Swift Package Manager to install KeychainManager using Xcode:

  1. Open your project in Xcode
  2. Click "File" -> "Swift Packages" -> "Add Package Dependency..."
  3. Paste the following URL: https://github.com/Echobird/KeychainManager
  4. Click "Next" -> "Next" -> "Finish"

TODO:

  1. Deal with Advanced Mode
  2. Allow Installation via CocoaPods, Carthage
  3. Some small refactor

GitHub

link
Stars: 3
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.0
3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics