浏览代码

Merge pull request #34 from kishikawakatsumi/string_url

Support passing String instead NSURL
kishikawa katsumi 10 年之前
父节点
当前提交
0d9f471140
共有 2 个文件被更改,包括 15 次插入7 次删除
  1. 8 0
      Lib/KeychainAccess/Keychain.swift
  2. 7 7
      README.md

+ 8 - 0
Lib/KeychainAccess/Keychain.swift

@@ -221,6 +221,14 @@ public class Keychain {
         self.init(options)
     }
     
+    public convenience init(server: String, protocolType: ProtocolType) {
+        self.init(server: NSURL(string: server)!, protocolType: protocolType)
+    }
+    
+    public convenience init(server: String, protocolType: ProtocolType, authenticationType: AuthenticationType) {
+        self.init(server: NSURL(string: server)!, protocolType: protocolType, authenticationType: .Default)
+    }
+    
     public convenience init(server: NSURL, protocolType: ProtocolType) {
         self.init(server: server, protocolType: protocolType, authenticationType: .Default)
     }

+ 7 - 7
README.md

@@ -36,7 +36,7 @@ keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
 #### Saving Internet Password
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
 ```
 
@@ -55,11 +55,11 @@ let keychain = Keychain(service: "com.example.github-token", accessGroup: "12ABC
 #### Create Keychain for Internet Password
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 ```
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS, authenticationType: .HTMLForm)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS, authenticationType: .HTMLForm)
 ```
 
 ### :key: Adding an item
@@ -184,7 +184,7 @@ if let error = keychain.remove("kishikawakatsumi") {
 ### :key: Label and Comment
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 keychain
     .label("github.com (kishikawakatsumi)")
     .comment("github access token")
@@ -371,7 +371,7 @@ if error != nil {
 #### Display all stored items if print keychain object
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 println("\(keychain)")
 ```
 
@@ -387,7 +387,7 @@ println("\(keychain)")
 #### Obtaining all stored keys
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 
 let keys = keychain.allKeys()
 for key in keys {
@@ -405,7 +405,7 @@ key: honeylemon
 #### Obtaining all stored items
 
 ```swift
-let keychain = Keychain(server: NSURL(string: "https://github.com")!, protocolType: .HTTPS)
+let keychain = Keychain(server: "https://github.com", protocolType: .HTTPS)
 
 let items = keychain.allItems()
 for item in items {