Skip to content

A sane way to work with the iOS Keychain in Swift.

License

Notifications You must be signed in to change notification settings

brunomacf/Locksmith

 
 

Repository files navigation

Locksmith

A sane way to work with the iOS Keychain in Swift.

Installation

Install the framework (reference c/o Alamofire)

  1. git submodule add https://github.com/matthewpalmer/Locksmith.git
  2. Open the newly created folder, 'Locksmith', in Finder
  3. Drag Locksmith.xcodeproj to the file navigator (left sidebar) of your project
  4. Click on your app's target, then click on Build Phases
  5. Follow the gif Locksmith iOS Keychain Library in Swift
  6. import Locksmith wherever you need it

Note: Due to a bug in Swift, the Swift Compiler - Code Generation Optimization Level for release builds has to be set to -Onone. Go here for more infromation on how to change it.

Quick Start

Save Data

Locksmith.saveData(["some key": "some value"], inService: "myService", forUserAccount: "myUserAccount")

Load Data

let (dictionary, error) = Locksmith.loadData(inService: "myService", forUserAccount: "myUserAccount")

Update Data

Locksmith.updateData(["some key": "another value"], inService: "myService", forUserAccount: "myUserAccount")

Delete Data

Locksmith.deleteData(inService: "myService", forUserAccount: "myUserAccount")

Custom Requests

To create custom keychain requests, you first have to instantiate a LocksmithRequest. This request can be customised as much as required. Then callLocksmith.performRequest on that request.

Saving

let saveRequest = LocksmithRequest(service: service, userAccount: userAccount, data: ["some key": "some value"])
// Customize the request
saveRequest.synchronizable = true
Locksmith.performRequest(saveRequest)

Reading

let readRequest = LocksmithRequest(service: service, userAccount: userAccount)
let (dictionary, error) = Locksmith.performRequest(readRequest)

Deleting

let deleteRequest = LocksmithRequest(service: service, userAccount: userAccount, requestType: .Delete)
Locksmith.performRequest(deleteRequest)

LocksmithRequest

Use these attributes to customize your LocksmithRequest instance.

If you need any more custom attributes, either create a pull request or open an issue.

Required

var service: String
var userAccount: String
var type: RequestType             // Defaults to .Read

Optional

var group: String?                // Used for keychain sharing
var data: NSDictionary?           // Used only for write requests
var matchLimit: MatchLimit        // Defaults to .One
var securityClass: SecurityClass  // Defaults to .GenericPassword
var synchronizable: Bool          // Defaults to false

About

A sane way to work with the iOS Keychain in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.0%
  • C++ 2.6%
  • Ruby 2.4%