Skip to content

Instantly share code, notes, and snippets.

@baileysh9
Last active September 17, 2015 14:24
Show Gist options
  • Save baileysh9/51ce37d9aff012c36974 to your computer and use it in GitHub Desktop.
Save baileysh9/51ce37d9aff012c36974 to your computer and use it in GitHub Desktop.
Save Login Keychain Swift
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