I have two classes, Model and ViewController. I have called a method in Model from ViewController on completion of which I need to execute the closure. This is What I have done:
Model.swift
typealias LoginCompletionBlock = () -> Void
func registerUser(username : String, emailID email : String, password userPassword : String, profileImage picture : UIImage, registrationMethod method : String, onCompletion completion : LoginCompletionBlock)
{
//Necessary code for an async request
}
// Delegate for getting the registration details
func registrationSucceededForUser(userID : String, withAccessToken token : String)
{
LoginCompletionBlock() // Error 'LoginCompletionBlock' is not constructible with '()'
}
And in ViewController.swift, I have called the function like this:
@IBAction func signUp(sender: UIButton)
{
model.registerUser(usernameTextField.text, emailID: emailTextField.text, password: passwordTextField.text, profileImage: profileImageView.image!, registrationMethod: "normal", onCompletion:{
() in
//Perform actions after login
}) //Error 'Bool' is not a subtype of 'Void'
}
I am just getting started with swift. Can anyone please guide me how to use the closures properly and how can I avoid this error. I need to pass a Bool as a parameter in the closure and no return type. I haven't included the Bool in the code since I was just trying to learn how to use closure.