KeychainItem
public struct KeychainItem
                A struct representation of a generic password item in the keychain.
The keychain query uses generic password for the item’s class, the serviceName property for the item’s service, and the account property for the item’s account name.
- 
                  
                  
String indicating the item’s service name.
Declaration
Swift
public let serviceName: String - 
                  
                  
String indicating the item’s account name.
Declaration
Swift
public let account: String - 
                  
                  
Creates a
KeychainIteminstance with the specified service name and account.Declaration
Swift
public init(serviceName: String, account: String)Parameters
serviceNameThe item’s service name.
accountThe item’s account name.
 - 
                  
                  
An access control object specifying that the keychain can only be accessed when the device is unlocked and constrain access to an item with either biometry or passcode.
Declaration
Swift
public static var accessControlWithUserPrescence: SecAccessControl? { get }Return Value
A SecAccessControl object specified with
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnlyas its protection type anduserPresenceas its flag. - 
                  
                  
Reads the keychain item and returns the data.
Throws
KeychainErrorthrown while trying to read the keychain item value.Declaration
Swift
public func read(context: LAContext? = nil, message: String? = nil) throws -> Data?Parameters
contextThe local authentication context.
messageDescription of the operation for which the app is attempting to authenticate.
Return Value
The keychain item data.
 - 
                  
                  
Reads the keychain item password and returns the string.
Throws
KeychainErrorthrown while trying to read the keychain item value.Declaration
Swift
public func readPassword(context: LAContext? = nil, message: String? = nil) throws -> String?Parameters
contextThe local authentication context.
messageDescription of the operation for which the app is attempting to authenticate.
Return Value
The keychain item password string.
 - 
                  
                  
Reads the keychain item and returns the json serialized object.
Throws
KeychainErrorthrown while trying to read the keychain item value.Declaration
Swift
public func readJSON(context: LAContext? = nil, message: String? = nil) throws -> [String : Any]?Parameters
contextThe local authentication context.
messageDescription of the operation for which the app is attempting to authenticate.
Return Value
The keychain item as a json serialized object distionary.
 - 
                  
                  
Writes data in the keychain item.
Throws
KeychainErrorthrown while trying to write the keychain item value.Declaration
Swift
public func write(data: Data, with access: SecAccessControl? = nil, context: LAContext? = nil) throwsParameters
dataThe data to be written in the keychain item.
accessThe access control object.
contextThe local authentication context.
 - 
                  
                  
Writes a password string in the keychain.
Throws
KeychainErrorthrown while trying to write the keychain item value.Declaration
Swift
public func writePassword(_ password: String, with access: SecAccessControl? = nil, context: LAContext? = nil) throwsParameters
passwordThe password string to be written in the keychain item.
accessThe access control object.
contextThe local authentication context.
 - 
                  
                  
Writes a json object in the keychain.
Throws
KeychainErrorthrown while trying to write the keychain item value.Declaration
Swift
public func write(json: [String : Any], with access: SecAccessControl? = nil, context: LAContext? = nil) throwsParameters
jsonThe json object dictionary to be written in the keychain item.
accessThe access control object.
contextThe local authentication context.
 - 
                  
                  
Deletes the keychain item value in the keychain.
Throws
KeychainErrorthrown while trying to delete the keychain item value.Declaration
Swift
public func delete() throws - 
                  
                  
Returns a dictionary containing the query for the keychain item.
The query uses generic password for the item’s class, the
serviceNameproperty for the item’s service, and theaccountproperty for the item’s account name.Declaration
Swift
public func keychainQuery() -> [String : Any]Return Value
A dictionary containing the query for the keychain item.
 
        KeychainItem Structure Reference