David Smith David Smith - 6 months ago 16
Swift Question

Issue with Swift Completion Handler Syntax

I have the following function provided in an open source piece of code:

public static func login(displayViewController: ViewController, completion: SimpleAPIResponse<Session> -> Void) {
authorize(displayViewController, completion: { result in
if let session = result.response.result {
session.getToken({ result in
Soundcloud.session = result.response.result
completion(result)
})
}
else {
completion(result)
}
})
}


For the life of me, I keep getting an insert "," error after "->", when that's obviously just the compiler wigging out due to a syntax issue.. when executing the following code:

Session.login(self, completion: SimpleAPIResponse<Session> -> Void)


Any help would be much appreciated. Thanks!

Answer
Session.login(self, completion: {(result: SimpleAPIResponse<Session>) -> Void in
        //Insert completion code

})

When using a completion handler, I guess I forgot to actually.. ya know.. use a completion block with code to execute upon completion.