[swift-evolution] Requesting default values for Cocoa/Cocoa Touch APIs
daniel at dimsumthinking.com
Sun Apr 10 06:14:38 CDT 2016
Thank you Erica,
Chris recently noted that UIColor.blackColor() will become UIColor.black() and dismissViewControllerAnimated(true, completion: nil) will become dismissAnimated(true, completion: nil).
This latter prompted me to wonder - as the first parameter’s name is flag and first labels will be exposed shouldn’t this be
dismiss(animated: true, completion: nil)
This, in turn led me to ask - don’t we most often want the first parameter to be true and the second to be nil? It is only an exceptional case where we don’t. Why don’t we take advantage of Swift’s default parameters to let this be
Similarly, UIButtons in UIKit stand out from UILabel’s and other widgets when we get and set titles/text. In the pair title(forState:), set(title:, forState:), we we took advantage of the default value .Normal for state then we’d have calls like this
and only call out the state in cases where we were setting the title for a non-Normal state.
Erica raises the general question that results: there are many defaults like this that would make Swift code read more naturally when working with non-exceptional cases and would call out when we are working with exceptional cases.
Is there a proper way in which to request such an audit/changes? I understand that that may be a Foundation/Cocoa Evolution issue and not a Swift evolution issue.
It does break code - but so does changing dismissViewControllerAnimated to dismissAnimated - it seems that paying the price once would be desirable.
> On Apr 8, 2016, at 1:40 PM, Erica Sadun <erica at ericasadun.com> wrote:
> Is there a best way to request default values for common Cocoa and Cocoa Touch APIs?
> Now that we're moving to Swift, the language supports defaults and omitted parameters
> but the ObjC APIs do not (yet) supply them.
> For example, dismissViewControllerAnimated(flag: true, completion: nil)
> could become dismissAnimated() when default values are available for flag and completion.
> There's a large-ish class of these boilerplate defaults and it would be nice if there were a way to
> be able to request them.
> cc'ing in Daniel S whose idea this is.
> Thanks, -- E
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution