Last active
September 20, 2016 18:13
-
-
Save nebiros/87b0fc3d52842f8ea55d9e8684f30ec4 to your computer and use it in GitHub Desktop.
Swift 3 – Resolving method ambiguity defining closures as a var
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
// objc's continue method signature: - (AWSTask *)continueWithBlock:(AWSContinuationBlock)block; | |
// swift translate it as: .continue(block: (AWSTask<AWSCognitoIdentityUserPoolSignUpResponse>) -> Any?) | |
// error: Ambiguous use of 'continue' | |
pool.signUp(username, | |
password: password, | |
userAttributes: attrs, | |
validationData: nil) | |
.continue { (task) -> Any? in | |
} | |
// typealias to the rescue… | |
typealias SignUpContinueClosure = (AWSTask<AWSCognitoIdentityUserPoolSignUpResponse>) -> (Any?) | |
var signUpContinueClosure: SignUpContinueClosure = { (task) in | |
return nil | |
} | |
// YAY!, no error! | |
pool.signUp(username, | |
password: password, | |
userAttributes: attrs, | |
validationData: nil) | |
.continue(signUpContinueClosure) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment