IDEA: Optional parameters bridge to Obj-C as distinct selectors

(Jared Sorge) #1

Hi everyone,
Over the last day or so I've been writing new methods in Swift with
default values in their parameters (which are optionals). Objective-C
doesn't honor the default method name argument so I have to specify the
argument to the method.

Contrived Example:

func addNumbers(first: Int, second: Int = 2) -> Int {
    return first + second

let number = addNumbers(5)
// 7

let numTwo = addNumbers(4, second: 1)
// 5

However, bridging the function to Objective-C yields only 1 selector:
`-(NSInteger) addNumbers:second:`

It would be great if, since there is a default argument, Objective-C
could see an additional selector: `-(NSInteger)addNumbers:`

This would call Swift and allow the default argument to be used. Has
there been any discussion of something like this? Thanks all!