Hi! 👋

We’re back. After a short hiatus, we are continuing Swift Weekly Brief every other week. 🎉 As Jesse mentioned, he will be taking a break from writing the newsletter. I will be taking over the curation of the newsletter for now, with the help of some awesome contributors and writers.

There is more great news: the Swift Forums are now live! They offer a more visual, searchable and navigatable way of browsing through the previous mailing lists. This will hopefully make the barrier for chiming in on everything Swift.org lower. Go have a look - and a huge congratulations to the team at Apple for realising this.

Starter tasks

  1. SR-6706: Swift should complain about weak references to classes that don’t support them
  2. SR-6691: Sequence.split should have a Lazy equivalent
  3. SR-6736: Enforce 16-bit limit for number of function parameters, number of tuple type element

Submit a task by sending a pull request or opening an issue.

Swift Unwrapped

While we’ve been away, Jesse and JP have discussed Improving Compilation Performance, Conditional Conformance (read more in the blog post here), and the State of String.

News and community

Apple released the first Xcode 9.3 beta, which will ship with Swift 4.1.

Apple released Swift Playgrounds 2, which lets you subscribe to third-party creators to browse and download their content directly within the app.

Ben Cohen wrote about Conditional Conformance, which is getting us closer to ABI stability, Swift 5’s major goal. (tweet)

Joe Groff’s talk at Swift Summit, Swift’s Reflective Underpinnings, has been posted and includes a transcript of the post as well.

Commits and pull requests

Greg Titus merged a pull request that allows you to fallthrough switch cases with the same variable bindings.

Doug Gregor merged a pull request to prevent invalid inputs that could cause a compiler crash.

Pavel Yaskevich opened a pull request that could speed up the type checking of complex expressions.

Slava Pestov merged a pull request that enables API resilience in the Standard Library. He’s been working on it for two and a half years (!). It was one of the three main goals to achieve ABI stability.

Chris Lattner merged a pull request that improves print performance - after reading a blog post by Ole Begemann from September 2016. 😱

Returned proposals

SE-0192: Frozen and Non-frozen Enums was reviewed and will return for revision.

The review of “SE 0192 - Non-Exhaustive Enums” had extensive discussion and has been returned for revision.

The proposal author, Jordan Rose, is working on a revised proposal that includes:

  • Alterations to the naming of the attributes.
  • New affordances for how switch statements work with non-exhaustive enums.

There will be a second round of review, but there is active discussion considering the latter point right now on swift-evolution on the thread “Handling unknown cases in enums”.

Proposals in review

SE-0194: Derived Collection of Enum Cases is under review.

We propose the introduction of a protocol, ValueEnumerable, to indicate that a type has a finite, enumerable set of values. Moreover, we propose an opt-in derived implementation of ValueEnumerable for the common case of a simple enum. The compiler will derive an implementation automatically for simple enums when the conformance is specified.

 
enum Ma: ValueEnumerable { case , , , , , , 🐎, 🐴 }

Ma.allValues         // returns some Collection whose Iterator.Element is Ma
Ma.allValues.count   // returns 8
Array(Ma.allValues)  // returns [Ma.马, .吗, .妈, .码, .骂, .麻, .🐎, .🐴]

SE-0195: Introduce User-defined “Dynamic Member Lookup” Types is under review.

This proposal introduces a new DynamicMemberLookupProtocol type to the standard library. Types that conform to it provide “dot” syntax for arbitrary names which are resolved at runtime - in a completely type safe way. It is simple syntactic sugar which has a non-invasive implementation in the compiler.

SE-0196: Compiler Diagnostic Directives is under review.

This proposal introduces #warning and #error directives that will cause the Swift compiler to emit a custom warning or an error during compilation.

Swift Forums

Michael Ilseman gave an update on the State of String in regard to the ABI, performance, ergonomics and more.

I’ve been working on implementing, optimizing, and improving String in preparation for ABI stability, and I thought I’d share the current status of String in Swift 5 and some potential directions to go. This is the product of conversations with open source contributors and my colleagues on the Swift standard library team at Apple.

Chris Eidhof pitched adding a function to toggle a Bool:

For Bool variables, it is common to want to toggle the state of the variable. In larger (nested) structs, the duplication involved can become especially annoying:

 
myVar.prop1.prop2.enabled = !myVar.prop1.prop2.enabled

It’s also easy to make a mistake in the code above if there are multiple Bool vars. [The proposed solution is to] add a method toggle on Bool:

 
extension Bool {
    mutating func toggle() {
        self = !self
    }
}

This allows us to write the example above without duplication:

 
myVar.prop1.prop2.enabled.toggle()

Finally

And finally… the Access Control debate continues.