|
10 tahun lalu | |
---|---|---|
Examples | 10 tahun lalu | |
KeychainAccess.xcworkspace | 10 tahun lalu | |
Lib | 10 tahun lalu | |
Screenshots | 10 tahun lalu | |
.gitignore | 10 tahun lalu | |
.travis.yml | 10 tahun lalu | |
KeychainAccess.podspec | 10 tahun lalu | |
LICENSE | 10 tahun lalu | |
README.md | 10 tahun lalu |
KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs exremely easy and much more palatable to use in Swift.
See also Playground.
let keychain = Keychain(service: "com.example.github-token")
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
.label("github.com (kishikawakatsumi)")
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
let keychain = Keychain(service: "com.example.github-token")
let keychain = Keychain(service: "com.example.github-token", accessGroup: "12ABCD3E4F.shared")
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS, authenticationType: .HTMLForm)
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
if let error = keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi") {
println("error: \(error)")
}
let token = keychain["kishikawakatsumi"]
let token = keychain.get("kishikawakatsumi")
let token = keychain.getString("kishikawakatsumi")
let data = keychain.getData("kishikawakatsumi")
First, get the failable
(value or error) object
let failable = keychain.getStringOrError("kishikawakatsumi")
1. check enum
state
switch failable {
case .Success:
println("token: \(failable.value)")
case .Failure:
println("error: \(failable.error)")
}
2. check error
object
if let error = failable.error {
println("error: \(failable.error)")
} else {
println("token: \(failable.value)")
}
3. check failed
property
if failable.failed {
println("error: \(failable.error)")
} else {
println("token: \(failable.value)")
}
keychain["kishikawakatsumi"] = nil
keychain.remove("kishikawakatsumi")
if let error = keychain.remove("kishikawakatsumi") {
println("error: \(error)")
}
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
.label("github.com (kishikawakatsumi)")
.comment("github access token")
Provides fluent interfaces
let keychain = Keychain(service: "com.example.github-token")
.label("github.com (kishikawakatsumi)")
.synchronizable(true)
.accessibility(.AfterFirstUnlock)
let keychain = Keychain(service: "com.example.github-token")
let keychain = Keychain(service: "com.example.github-token")
.accessibility(.AfterFirstUnlock)
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
let keychain = Keychain(service: "com.example.github-token")
keychain
.accessibility(.AfterFirstUnlock)
.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
let keychain = Keychain(service: "com.example.github-token")
.accessibility(.WhenUnlocked)
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
let keychain = Keychain(service: "Twitter")
keychain
.accessibility(.WhenUnlocked)
.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
let keychain = Keychain(service: "com.example.github-token", accessGroup: "12ABCD3E4F.shared")
let keychain = Keychain(service: "com.example.github-token")
.synchronizable(true)
keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
let keychain = Keychain(service: "com.example.github-token")
keychain
.synchronizable(true)
.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
println("\(keychain)")
=>
[
[authenticationType: Default, key: kishikawakatsumi, server: github.com, class: InternetPassword, protocol: HTTPS]
[authenticationType: Default, key: hirohamada, server: github.com, class: InternetPassword, protocol: HTTPS]
[authenticationType: Default, key: honeylemon, server: github.com, class: InternetPassword, protocol: HTTPS]
]
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
let keys = keychain.allKeys()
for key in keys {
println("key: \(key)")
}
=>
key: kishikawakatsumi
key: hirohamada
key: honeylemon
let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
let items = keychain.allItems()
for item in items {
println("item: \(item)")
}
=>
item: [authenticationType: Default, key: kishikawakatsumi, server: github.com, class: InternetPassword, protocol: HTTPS]
item: [authenticationType: Default, key: hirohamada, server: github.com, class: InternetPassword, protocol: HTTPS]
item: [authenticationType: Default, key: honeylemon, server: github.com, class: InternetPassword, protocol: HTTPS]
iOS 7 or later OS X 10.9 or later
KeychainAccess is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KeychainAccess'
KeychainAccess is available through Carthage. To install it, simply add the following line to your Cartfile:
github "kishikawakatsumi/KeychainAccess"
kishikawa katsumi, kishikawakatsumi@mac.com
KeychainAccess is available under the MIT license. See the LICENSE file for more info.