AWS iOS Swift 3 Cognito Type does not conform to protocol

554 views Asked by At

Hi im using AWS Mobile hub in iOS i followed the introductions to aut with cognito. It says I have to import the user pool files from the sample. I did so, but this throws me an error:

extension SignInViewController: AWSCognitoIdentityPasswordAuthentication {

    func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AnyObject>) {
        self.passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
    }

    func didCompleteStepWithError(_ error: Error?) {
        if let error = error {
            DispatchQueue.main.async(execute: {
                UIAlertView(title: "ERROR",
                    message: error.localizedDescription,
                    delegate: nil,
                    cancelButtonTitle: "Ok").show()
            })
        }
    }
}

Errors:

Type 'SignInViewController' does not conform to protocol 'AWSCognitoIdentityPasswordAuthentication'

Also:

Protocol requires function 'getDetails(_:passwordAuthenticationCompletionSource:)' with type '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> Void'; do you want to add a stub? (AWSCognitoIdentityProvider.AWSCognitoIdentityPasswordAuthentication)

and:

Candidate has non-matching type '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> ()'

1

There are 1 answers

1
Bogdan Farca On BEST ANSWER

According to the docs, any class conforming to AWSCognitoIdentityPasswordAuthentication should implement :

– getPasswordAuthenticationDetails:passwordAuthenticationCompletionSource
– didCompletePasswordAuthenticationStepWithError

You don't implement them, hence the error.

EDIT Yes, you're right, the function signatures changed in Swift 3 (see here).

They should be like this :

func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>)
func didCompleteStepWithError(_ error: Error?)

Looks like your version of the first func is slightly different.