두 클래스, Model
및 ViewController
이 있습니다. 나는 클로저를 실행해야 할 때 ViewController
에서 Model
의 메소드를 호출했습니다.오류를 일으키는 클로저 Swift
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 '()'
}
그리고 ViewController.swift
에, 나는이 같은 기능이라고했다 : 난 그냥 신속로 시작하고
@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'
}
를이 내가했던 것입니다. 누구나 폐쇄를 올바르게 사용하는 방법을 알려주고 어떻게이 오류를 피할 수 있습니까? 클로저에 매개 변수로 Bool
을 전달해야하며 반환 유형이 없습니다. 내가 클로저를 사용하는 법을 배우려고 할 때부터 코드에 Bool
을 포함시키지 않았다.
죄송합니다. 찾지 못했습니다. 올바른 코드 스 니펫을 보여 주시겠습니까? –
예제를 추가했습니다. 이 경우 "성공"은 Bool로 암시 적으로 입력 된 함수에 대한 인수입니다. –
자,이 코드를 사용해 보겠습니다. –