Last week in Swift Evolution
Week of Jan 18, 2016
Published on
Here’s a summary of selected updates from last week from the Swift Evolution repo and mailing list:
Under review this week
-
Previously: Week of Jan 11.
In Swift 3, the look of the language is getting a redesign, which is governed by three interlinked proposals:
-
The changes proposed in the other two proposals are motivated by these API design guidelines. The guidelines themselves are here: proposed version, in-development version.
Discussion on the guidelines included these points:
-
There’s a guideline that says:
When a mutating method is described by a verb, name its non-mutating counterpart according to the “ed/ing” rule, e.g. the non-mutating versions of
x.sort()
andx.append(y)
arex.sorted()
andx.appending(y)
.But as Joe Groff pointed out, English is a weird language, so while it works for sort, it doesn’t work as unambiguously for split, cut, etc.
-
As per the guidelines, redundant type names should be removed from function names (like
removeElement()
becomesremove()
), except when the type of the argument doesn’t sufficiently describe what it is (likeaddObserver()
, which should remain as is).As per the proposal, the function should continue to be invoked as
addObserver(obj, forKeyPath: path)
. David Owens suggested that invoking it asadd(observer: obj, forKeyPath: path)
would read better. -
While we’re here, why should enums remain UpperCamelCase? Like other non-types, shouldn’t they be lowerCamelCase?
-
-
These are some of the changes planned for how Obj-C APIs are accessed from Swift 3:
- Prune redundant type names from function arguments, so it’s
remove(member: Element)
rather thanremoveElement(member: Element)
- Prepend
is
to Boolean properties, so it’sapplication.isStatusBarHidden
rather thanapplication.statusBarHidden
(See all changes like this) - Strip the
NS
prefix from Foundation APIs, so it’sRect
rather thanNSRect
(See all changes like this)
- Prune redundant type names from function arguments, so it’s
-
These are some of the changes planned for the Swift Standard Library:
- Remove
Type
suffix from protocol names, so it’sCollection
, notCollectionType
- Generators are now called iterators. For example,
SequenceType.generate() -> Generator
becomesSequenceType.iterator() -> Iterator
. - Non-mutating methods shouldn’t read as command-verbs. So
sort()
that currently returns a sorted list becomessorted()
.
- Remove
-
Accepted proposals
-
Previously: Weeks of Dec 28, Jan 4, Jan 11.
The Swift Package Manager team’s proposal to include tests in Swift packages was accepted.
This proposal doesn’t support arbitrary test frameworks. Rick Ballard, the review manager, says:
This initial proposal includes support for using XCTest; we expect that adding generic support for other testing frameworks will be discussed in an upcoming proposal.
-
Naming functions with argument labels
Previously: Weeks of Dec 28, Jan 11.
Doug Gregor’s proposal to identify functions with argument labels was accepted. The code would look something like this:
let someView = UIView() // Assign function to variable let fn1 = someView.insertSubview(_:aboveSubview:) // Call assigned function fn1(subview1, aboveSubview: subview2)
Doug Gregor already has a working implementation of this proposal.
Review discussions
-
Referencing Obj-C selectors cleanly
Previously: Week of Jan 11.
The syntax originally proposed to refer to Obj-C selectors was
Selector(foo:)
. Last week, the Swift team felt that this particular syntax was hard to implement. Joe Groff says:We discussed this proposal during our core team review meeting, and concerns were raised about the implementability of the proposed ‘Selector(Type.method)’ syntax. Producing the selector is something that can’t quite be modeled as a real initializer, so the type checker would have to perform heroics to disambiguate a selector literal reference from a proper initializer call. We recommend reconsidering alternative syntactic forms for referencing the selector.
The current favorite alternate syntax for this is
#selector(foo:)
.
Merged proposal implementations
- The associatedtype implementation was merged
Other weeklies
- Jesse Squires’ Swift Weekly Brief Issue #6 covers the week till last Thursday