Coder Social home page Coder Social logo

simplekeychain's Introduction

SimpleKeychain

SimpleKeychain is a Swift package providing a convenient interface for interacting with the iOS Keychain. It is designed to simplify common tasks such as storing and retrieving sensitive data securely.

Features

  • Generic Storage: Store and retrieve generic items securely in the Keychain.
  • Type-Safe Retrieval: Retrieve stored items with type safety using Swift generics.
  • Item Class Types: Support for different item class types, such as generic or internet password.
  • Duplicate Item Handling: Automatically handles duplicate items during storage.

Installation

Swift Package Manager

To integrate SimpleKeychain into your Xcode project using Swift Package Manager, add the following dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/yourusername/SimpleKeychain.git", from: "0.1.0")
]

Usage

Initialization

// Initialize SimpleKeychain with optional service and access group parameters
let keychain = SimpleKeychain(service: "com.yourapp.keychain", accessGroup: "your.access.group")

Storing and Retrieving Data

// Store an item
try keychain.set("YourItem", for: "YourKey")

// Retrieve an item
let retrievedItem: String = try keychain.get(key: "YourKey")

Deleting and Clearing

// Delete a specific item
try keychain.delete("YourKey")
// Or alternatively set a nil value
try keychain.set(nil, for: "YourKey")

// Clear all items of a specific class type
try keychain.clear(ofType: .generic)

Error Handling

All operations that interact with the Keychain may throw errors of type SimpleKeychainError. Ensure to handle these errors appropriately in your code.

do {
    // Perform Keychain operation
} catch let error as SimpleKeychainError {
    // Handle the error
    print("Keychain operation failed: \(error.localizedDescription)")
} catch {
    // Handle other errors
    print("An unexpected error occurred: \(error.localizedDescription)")
}

Work based on the following contributions

Bruno Lorenzo

KeychainAccess

KeychainSwift

Swift Discovery

License

SimpleKeychain is released under the MIT License. See LICENSE for details.

simplekeychain's People

Contributors

lukacs-m avatar mlukbot avatar ntnhon 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.