fc6d06bc80f31480cbfeff7be5f952cdeb3c5889
Locksmith
A sane way to work with the iOS Keychain in Swift.
Installation
Locksmith is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Locksmith"
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
Author
matthewpalmer, matt@matthewpalmer.net
License
Locksmith is available under the MIT license. See the LICENSE file for more info.
Languages
Swift
97.9%
Ruby
1.9%
Objective-C
0.2%