Last active
September 17, 2015 14:24
-
-
Save baileysh9/51ce37d9aff012c36974 to your computer and use it in GitHub Desktop.
Save Login Keychain Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func saveLogin(password: NSData, userName:String, service:String) | |
{ | |
//Create the query | |
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, userName, password], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecAttrAccountValue, kSecValueDataValue]) | |
// Delete any existing items | |
SecItemDelete(keychainQuery as CFDictionaryRef) | |
//Add the query to the keychain | |
let status: OSStatus = SecItemAdd(keychainQuery as CFDictionaryRef, nil) | |
print(status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment