Swift how to return function with same argument usage of default value and label

I want to return a function and invoke it as bb in the code

func bb(a: Int, b: String = "b") {
  print(a, b)

typealias FnOfBb = (Int, String) -> Void

func cc() -> FnOfBb {
  return bb

bb(a: 1) // is ok

cc()(a: 1) // desired, but show Error: Extraneous argument label 'a:' in call  and  Missing argument for parameter #2 in call

cc()(1, "str") // is ok, but different of bb

You can simply add the labels in your typealias definition:

typealias FnOfBb = (a: Int, b: String) -> Void

Terms of Service

Privacy Policy

Cookie Policy