iOS Keychain的Swift封装:Locksmith
jopen
9年前
一个强大,面向协议的库,用于在Swift中能够使用 iOS Keychain 。
Locksmith与其它keychain封装的不同之处在于?
- Locksmith’s API is both super-simple and deeply powerful
- Provides access to all of the keychain’s metadata in a type-useful way viaResultTypeprotocols—save anNSDate, get anNSDateback (without typecasting!)
- Add functionality to your existing types for free
- Useful enums and Swift-native types
Installation
CocoaPods
Locksmith is available through CocoaPods. To install Locksmith for Swift 2, simply add the following line to your Podfile:
pod 'Locksmith'
Swift 1.2 support is available via the1.2.2branch.
Quick start
Save data
try Locksmith.saveData(["some key": "some value"], forUserAccount: "myUserAccount")
Load data
let dictionary = Locksmith.loadDataForUserAccount("myUserAccount")
Update data
- as well as replacing existing data, this writes data to the keychain if it does not exist already
try Locksmith.updateData(["some key": "another value"], forUserAccount: "myUserAccount")
Delete data
try Locksmith.deleteDataForUserAccount("myUserAccount")