[swift-evolution] IDEA: Optional parameters bridge to Obj-C as distinct selectors

Jared Sorge jared at jsorge.net
Tue Jul 12 15:48:08 CDT 2016

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!

More information about the swift-evolution mailing list