Fabrizio Bartolomucci Fabrizio Bartolomucci - 10 months ago 25
Swift Question

'Extra Argument in Call' in completion call in Swift

I am trying to return a simple tuple in the completion of a function as in the following code:

func meditatorForId(id:Int, completion:((Meditator, Int)? -> Void)){
var counter:Int=0
for meditator in SanghaModelProvider.sharedProvider().meditatorsArray{
if meditator.id == id{
completion(meditator, counter)

Yet I get 'Extra Argument in Call' on the completion call line without getting more explanations. What could be the problem?


You are trying to call completion with two arguments, but it should be a single argument with the tuple:

completion((meditator, counter))


let tuple = (meditator, counter)

If you would prefer to call it with two parameters then change your function to this:

func meditatorForId(id:Int, completion:((Meditator?, Int?) -> Void)) {

Then this will work:

completion(meditator, counter)

but you will have to change the 2nd call to:

completion(nil, nil)