Hello everyone, I am fairly new to Swift and I've been working on a couple of things recently.
Even after changing .textContentType(.username) and .keyboardType(.emailAddress), the autofill function still does not work for my project. I thought of changing and updating the whole Keychain class and started to use this wrapper https://auth0.github.io/SimpleKeychain/documentation/simplekeychain/. The class that I use to handle user's data uses an old objective-c class (oldKeychain) with different functions.
func load() -> Promise<(String?, String?, String?)> {
return Promise { seal in
// Load user password
oldKeychain.loadCredentials(forKey: userPasswordKey, reasonString: "") { (errorCode, email, userPassword) in
if errorCode == errSecSuccess {
// Load device password
oldKeychain.loadCredentials(forKey: self.devicePasswordKey, reasonString: "") { (errorCode, _, devicePassword) in
// Device password is optional, may not exist
seal.fulfill((email, userPassword, devicePassword))
}
}
else {
if errorCode == errSecUserCanceled {
// Biometrics cancelled
seal.reject(AppError.keychainBiometricsCancelled)
} else {
seal.reject(AppError.credentialsLoadUserPasswordFailed)
}
}
}
}
}
After changing the old reference to old class and calling different function the code structure would possibly look like this.
func load() -> Promise<(String?,String?,String?)> {
return Promise { seal in
// Load user password
do {
let value = try simpleKeychain.string(forKey: userPasswordKey) {(errorCode, email, userPassword) in
if errorCode == errSecSuccess {
// Load device password
let value = try simpleKeychain.string(forKey: devicePasswordKey) { (errorCode, _, devicePassword) in
// Device password is optional, may not exist
seal.fulfill((email,userPassword,devicePassword))
}
}
else {
if errorCode == errSecUserCanceled {
// Biometrics cancelled
seal.reject(CVAppError.keychainBiometricsCancelled)
} else {
seal.reject(CVAppError.credentialsLoadUserPasswordFailed)
}
}
}
}
}
}
However I keep getting Extra trailing closure passed in call error in this section of code
let value = try simpleKeychain.string(forKey: userPasswordKey) {(errorCode, email, userPassword) in
I tried to return just one value which did not throw any build errors but I have to be returning all 3 (email,userPassword,devicePassword).
Does anyone have any tips on how to rewrite the code so that I do not get any closure errors and can return all 3 parameters with the use of new wrapper ?
THANKS !!!