Usage of closures with multiple arguments in swift
Posted
by
Nilzone-
on Stack Overflow
See other posts from Stack Overflow
or by Nilzone-
Published on 2014-06-09T21:10:08Z
Indexed on
2014/06/09
21:24 UTC
Read the original article
Hit count: 267
This question is largely based on this one:
The main difference being that I want to pass in arguments to the closure as well. Say I have something like this:
func someFunctionThatTakesAClosure(completionClosure: (venues: Dictionary<String, AnyObject>, error: NSError) -> ()) {
// function body goes here
var error: NSError?
let responseDictionary: Dictionary<String, AnyObject> = ["test" : "test2"]
completionClosure(venues: responseDictionary, error: error!)
}
No error here. But when I call this function in my main view controller I have tried several ways but all of the result in different errors:
venueService.someFunctionThatTakesAClosure(completionClosure(venues: Dictionary<String, AnyObject>, error: NSError){
})
or like this:
venueService.someFunctionThatTakesAClosure((venues: Dictionary<String, AnyObject>, error: NSError){
})
or even like this:
venueService.someFunctionThatTakesAClosure(completionClosure: (venues: Dictionary<String, AnyObject>, error: NSError) -> (){
});
I'm probably just way tired, but any help would be greatly appreciated!
© Stack Overflow or respective owner