1

Let's say we have a function with defalut parameter values:

// function with default parameter values
func a(m:Int = 0, n:Int = 1) {
  print(m, n)
}

a()         // 0 1
a(m:2)      // 2 1
a(n:3)      // 0 3
a(m:4, n:5) // 4 5

Now I want to return exactly the same function from another function:

func b() -> (Int,Int)->Void {
  func a(m:Int = 0, n:Int = 1) {
    print(m, n)
  }
  return a    // function returned
}

let a2 = b()

a2(m:4, n:5)  // ⛔ error: extraneous argument labels 'm:n:'
a2(4)         // ⛔ error: missing argument for parameter #2  
a2(4,5)       // OK

Now, neither can I use argument labels nor can I use default values for parameters, why?

It seems that function a2() is a totally different thing from function a(), what's going on behind the scenes?

lochiwei
  • 1,240
  • 9
  • 16
  • Closures cannot have default values (and no external parameter names). I am fairly sure that this has been asked and answered before. Still searching ... – Martin R Feb 06 '19 at 15:01
  • 1
    https://stackoverflow.com/questions/39613272/xcode-8-function-types-cannot-have-argument-label-breaking-my-build – Fabio Felici Feb 06 '19 at 15:02
  • 2
    https://stackoverflow.com/q/45258621/1187415: “Only functions can have default parameters” – Martin R Feb 06 '19 at 15:04

0 Answers0