This issue, I’ll keep this short and sweet. I hope you’re all staying healthy and at home.

Enjoy the issue!

Interested in sponsoring Swift Weekly Brief? Learn more here.

Starter tasks

  • SR-12460 [Compiler] Declaring an operator inside an extension without a name crashes the compiler

Podcasts

In episode 371 of the Accidental Tech Podcast (ATP), Marco Arment, Casey Liss, John Siracusa, and Chris Lattner discuss TensorFlow, Multi-Level Intermediate Representation, Swift’s future and more.

In episode 8 of the Swift Community Podcast, Kate Castellano, Paul Hudson, Chris Lattner, and Bas Broek discuss Swift for Good, a book on Swift with 100% of all revenue going to charity.

News and community

Ted Kremenek shared that Apple is sponsoring PLDI this year — the Programming Language Design and Implementation conference. As Ted said:

Swift has drawn inspiration from many programming languages and those of us working on Swift are proud to be part of the broader programming language community.

Mattt wrote an article on swift-log, a community-driven, open-source standard for logging in Swift, backed by Apple.

Furthermore, Mattt announced swift-doc, generating documentation for Swift projects.

Jasdev Singh wrote an article talking about the “fusion” term he struggled to build intuition around until he read through Combine’s documentation.

Saleem Abdulrasool announced SwiftNIO is now running on Windows!

Commits and pull requests

Owen Voorhees merged a pull request which implements SE-0276: Multi-Pattern Catch Clauses. Awesome!

Robert Widmann merged a pull request with a new approach for recording incremental build dependencies using the request evaluator, paving the way for faster builds in the future. 🏎

Suyash Srijan merged a pull request implementing SE-0268: Refine didSet Semantics, as well as a pull request implementing SE-280: Enum cases as protocol witnesses.

Stephen Canon merged a pull request implementing SE-0277: Float16.

Accepted proposals

SE-0280: Enum cases as protocol witnesses was accepted.

Almost all of the feedback we received was in favor of making this change, and the Core Team is convinced that this closes an unnecessary semantic gap between enums and other types.

Proposals in review

SE-0281: @main: Type-Based Program Entry Points is under review.

A Swift language feature for designating a type as the entry point for beginning program execution. Instead of writing top-level code, users can use the @main attribute on a single type. Libraries and frameworks can then provide custom entry-point behavior through protocols or class inheritance.

Swift Forums

Dave Abrahams pitched a proposal to introduce a better data pretty-printer.

With this post, I hope to open a discussion of the design requirements for a library, similar to Python’s pprint, that could eventually be incorporated into the standard library and inform the design of many parts of the Swift ecosystem.

There are many contexts—from educational/research tools like Playgrounds and Colab Notebooks to industrial programming activities like debugging and logging, in which it’s important to be able to easily visualize/understand Swift data structures. For consumption by actual humans, though, Swift’s facilities for formatting data leave a lot to be desired.

Jon Gilbert pitched a proposal for Property initialization using a KeyPath within an init method.

Given:

struct Foo {
    let bar: Int
}

In an init method, you can do:

init() {
    self.bar = 42
}

However, unfortunately, you cannot do:

init() {
    self[keyPath: \.bar] = 42
}

This error is thrown: “self used before all stored properties are initialized.”

This seems like a compiler bug, or at least, a counter-intuitive aspect of keypaths. If a property setter works on self before its properties are initialized, then a keyPath subscript should also work.

Shawn Baek pitched a proposal for table style printing for two dimensional Arrays, Dictionaries, and tuples.

The standard library print doesn’t support table-style output. So it is hard to check the data in the 2D array.

Here is my suggestion.

print(
    table: ["Good", "Very Good", "Happy", "Cool!"], 
    header: ["Wed", "Thu", "Fri", "Sat"]
)

Output:

+----+---------+-----+-----+
|Wed |Thu      |Fri  |Sat  |
+----+---------+-----+-----+
|Good|Very Good|Happy|Cool!|
+----+---------+-----+-----+

Finally

Late at work, cleaning the cat’s litter box.