We are only a few days away from WWDC 2017! This week the Swift repository saw its 10,000th pull request. Things have been more quiet than usual, but we did get a great update to the WWDC iOS app. 😅 I did not get a ticket, but I will be hanging out in San Jose for most of the week — if you are attending it would be great to meet in person! Aside from WWDC, there are a number of other events happening. For the Swift community, check out Realm’s WWDC Swift Panel and the SwiftCoders meet & greet at AltConf. See you next week!

有兴趣赞助 Swift Weekly Brief?点击这里

Starter tasks

  • SR-5018: Mark +new as SWIFT_UNAVAILABLE when -init is SWIFT_UNAVAILABLE.
  • SR-4949: No error for using as patterns with CoreFoundation types

Swift Unwrapped

Episode 13: WWDC Predictions

This week, we share our hopes and expectations for the Swift language at WWDC 2017!

News and community

Caleb Davenport highlighted a somewhat undesirable change coming in Swift 4. Due to proposal SE-0110 (but really SE-0029), N-ary tuples are no longer expanded to N arguments in a closure (the “tuple splat behavior”). This means closures will receive a single tuple parameter and you’ll have to expand them manually. Joe Groff noted that this was a source of bad type-checker performance and sympathized about rolling back this syntactic sugar.

In a recent episode of the SwiftCoders podcast, Garric Nahapetian interviews Robert Widmann (aka @CodaFi_), a Swift compiler intern and Swift open source contributor.

Apple have released a free, beginner-level, 900 page book “App Development with Swift” and related teaching materials. In total, it looks like there are 2 books and 5 teacher guides in the series. Hat tip @cocoawithlove.

Thanks to JP Simard for showing me a Swift IDE for macOS called Robotary, which you can use to program LEGO MINDSTORMS EV3 robots. It’s been around for some time and hasn’t been updated since last September, but it looks pretty cool. 😎 Also — lego robots. 😱

Commits and pull requests

Dave Abrahams opened a pull request with his overhaul changes to String.Index. See the mailing list section below for details on the proposal.

Amr Aboelela wrote a build-toolchain script for Android, similar to the existing build-toolchain script for Darwin. This should be useful for anyone experimenting with Swift on Android.

Ben Cohen added benchmarks for equating/comparing substrings.

Accepted proposals

SE-0179: Swift run Command was accepted with revisions.

The proposal has been accepted with revision for Swift 4. There was unanimous support for the proposal in general, but there was discussion on three major points:

  1. The utility of having both “run – …” and “run command arg1 arg2” forms.
  2. Whether to build by default.
  3. The confusion of having two commands which “change the working directory’.

1) The -- command syntax.

We decided we will not support the: swift run -- arg1 arg2 arg3 syntax, for packages with only one executable, because we felt it was not sufficiently useful versus spelling the command name, and we didn’t want to unnecessarily have two ways to do the same thing. This behavior would be additive if it proved to be worth adding down the road.

We will support the no argument swift run form in the proposal, since it is unambiguous.

2) Whether to build by default.

This behavior is consistent with our existing behavior for swift test, and so we believe this is the correct behavior for this proposal.

3) The confusion over the --chdir and --in-dir arguments.

We agreed with the feedback that this was confusing, and so decided to:

  • Rename the existing --chdir argument to --package-path and change it to simply define the package to work on instead of as a side effect of changing directories. We chose –package-path over –package to leave room for --package <NAME> syntax in the future, should we have an index. We will make this change and deprecate --chdir in Swift 4, and remove it at a later date.
  • Remove the --in-dir argument, and instead leave it up to commands themselves to manage interaction with the working directory.
  • Explicitly specify the behavior of swift run to always execute the command in the directory from with swift run was run.

In combination, these choices allow swift run foo ... to generally behave as it would if the package’s products had been built, installed, and run via the shell normally. We believe this allows swift run ... to integrate with the shell as naturally as possible.

Thank you to everyone who participated!

Returned proposals

There was no email on the lists, but SE-0177: Add clamp(to:) to the stdlib was returned for revision. Given that this hasn’t been communicated to swift-evolution (a review never started in the first place), my guess is that this is simply out-of-scope for Swift 4. That, or everyone is too busy preparing for WWDC. 😅

Mailing lists

Dave Abrahams pitched a proposal to overhaul String.Index. You can find the draft here and the pull request here that implements the changes!

Today String shares an Index type with its CharacterView but not with its UTF8View, UTF16View, or UnicodeScalarView. This proposal redefines String.UTF8View.Index, String.UTF16View.Index, and String.CharacterView.Index as typealiases for String.Index, and exposes a public encodedOffset property and initializer that can be used to serialize and deserialize positions in a String or Substring.

[…]

The result is a great deal of API surface area for apparently little gain in ordinary code, that normally only interchanges indices among views when the positions match up exactly (i.e. when the conversion is going to succeed). Also, the resulting code is needlessly awkward.

Continue reading…

Finally

And finally — we cannot be trusted with state.