We’re very happy to re-introduce the newsletter’s mail subscriptions, so that you can once again receive Swift Weekly Brief in your inbox. If you haven’t yet and are interested, you can subscribe here.

Enjoy the newsletter and have a great weekend and week!

Starter tasks

  • SR-8703 [Tensorflow] Deabstraction should properly diagnose recursion
  • SR-8706 [Compiler] Fix up parseDependencyFile to not crash on invalid YAML
  • SR-8707 [Compiler] Write out swiftdeps files atomically
  • SR-8720 [Package Manager] Add –hide-build option to swift run

News and community

Ted Kremenek has written an overview of the release process of Swift 5.0, including the goals and an estimated schedule.

Mike Ash wrote a blog post on the Swift.org blog, explaining how Mirror works.

Timac wrote a blog post that measures Apple’s use of Swift in iOS 12. 66 binaries are now using Swift! 🎉

Bruno Rocha wrote a blog post on how Swift 4.2’s CaseIterable works internally.

Commits and pull requests

Lily Vulcano opened a pull request that merges improvements from the Core Foundation version found in Mojave and iOS 12 into Swift Foundation.

Albert Aleksieiev merged a pull request that adds Android support to SwiftNIO! 💪

Michael Gottesman merged a pull request bringing performance improvements to the standard library. 🏎

Accepted proposals

SE-0221: Character Properties was acceptance status was updated.

The core team has resolved to change the status of this proposal to accepted with modification, deferring the .isEmoji property to a later proposal.

The core team still believe it is a useful feature for the standard library, but needs more investigation that should not hold up the rest of this proposal.

In addition, the proposal will drop the source-breaking change to the existing FixedWidthInteger.init?. While this would be the preferred naming for a newly proposed initializer, it doesn’t clear the bar for a source-breaking change for Swift 5.

SE-0228: Fix ExpressibleByStringInterpolation was accepted with a small amendment.

Feedback was overwhelmingly positive, and the proposal is accepted with one small amendment to provide a default implementation of init(stringLiteral:) for types that conform to ExpressibleByStringInterpolation.

Proposals in review

SE-0229: simd vectors is under review.

This proposal would expose a common subset of operations on the SIMD types supported by most processors in the standard library. It is based on Apple’s <simd/simd.h> module, which is used throughout Apple’s platforms as the common currency type for fixed-size vectors and matrices. It is not a complete re-implementation; rather it provides the low-level support needed to import any such library, and tries to make a number of things much nicer in Swift than they are in C or C++.

SE-0230: Flatten nested optionals resulting from try? is under review.

Swift’s try? statement currently makes it easy to introduce a nested optional. Nested optionals are difficult for users to reason about, and Swift tries to avoid producing them in other common cases.

This document proposes giving try? the same optional-flattening behavior found in other common Swift features, to avoid the common occurrence of a nested optional.

It’s currently quite easy to end up with a nested Optional type when using try?. Although it is valid to construct a nested optional, it is usually not what the developer intended.

Swift Forums

Alejandro Alonso pitched a proposal to make it easier to have default implementations in protocols, without the need of an extension.

I’ve been working on implementing Default Implementation in Protocols and I have a working early implementation of the feature.

What this feature allows is that you can now declare a default implementation of a requirement from the protocol:

protocol Animal {
  func makeNoise() {
    print("Bark!")
  }
}

struct Dog: Animal {}

let sparky = Dog()
sparky.makeNoise() // Bark!

Peter Camb shared an issue, which is a bug in Swift that can currently not be solved through Swift iself.

I’m hitting this issue in my NSOpenSavePanelDelegate in a Sandboxed Mac app.

I need to get a reference to the sender as a Panel and set the directory.

/* NSSavePanel/NSOpenPanel: Gets and sets the directoryURL shown. */
@available(OSX 10.6, *)
open var directoryURL: URL?

All of my as? casts fail because the Sandbox uses a private subclass for these items.

Jordan Rose:

This is a longstanding bug, but it looks like we don’t have a JIRA bug for it. [..] it’s very similar to SR-5475 (which is about optional properties of protocols). I don’t think we have a good workaround other than defining a little static inline function in Objective-C that will do the call for you without trying to check anything.

NS_SWIFT_NAME(setDirectoryURL(_:for:))
static inline void setDirectoryURLForPanel(id panel, NSURL * _Nonnull url) {
  NSSavePanel *realPanel = (NSSavePanel *)panel;
  realPanel.directoryURL = url;
}

An alternate approach in this specific case would be to file a bug against Apple that the sender here is not an instance of NSOpenPanel or at least NSSavePanel.

Finally

Making all sorts of progress on variadic generics. 🦄