[SR-1970] Default value annotations for Objective-C parameters
| Previous ID | SR-1970 |
| Radar | rdar://problem/24733624 |
| Original Reporter | @jadengeller |
| Type | Improvement |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Improvement, ClangImporter |
| Assignee | None |
| Priority | Medium |
md5: 30da7bb27610f949ed4e7f6131ee4a0c
Issue Description:
Adding default parameters to an Objective-C function currently requires either (a) marking the function as `NS_REFINED_FOR_SWIFT` and rewriting it with the default parameters or (b) overloading the function in extensions adding the default parameters (though the number of overloads scales exponentially with the number of defaulted parameters).
It would be very useful to be able to annotate an Objective-C API with something like `NS_SWIFT_DEFAULT()` where the parameter may be either `nil`, a string literal, or an integer literal. This would greatly ease the Swifitication of Objective-C API without rewriting their signatures in Swift. Since it would only work for a few basic literal types, there's no need to support arbitrary Swift code in Objective-C. Alternatively, the macro could support any type that can be represented in Objective-C (types would be automatically bridged to the proper Swift type).
If adding default value annotations to Objective-C is controversial, maybe it would be better to allow default values to be specified separately from the function declaration so they could be added after the fact. My preference is definitely the former though since this seems potentially problematic.