WWDC 2023

Here are 20 sessions I’m watching from WWDC this year. Naturally, I try to select sessions that I think will have direct impact on my day-to-day work. Because of this, I’ve chosen to mostly skip the Vision Pro-related content for now.

Swift

Notes
  • Swift 5.9 allows if/else and switch statements to be used as expressions. This means instead of using ternarys, for example, you can do:
  • let x = 
    	if isRoot == 0 { "zero" }
    	else if isRoot > 0 { "greater then zero" } 
  • <each Result> type parameter pack. Functions can now take multiple generic arguments, and return a tuple of the matching type results, instead of needing to define new functions for number of arguments.
  • Macros. Look like functions, but introduced with the marco keyword.
  • public macro assert(_ condition: Bool)

    Freestanding macros can be used anywhere, while attached macros are associated with specific elements in code.

  • Foundation is being rewritten in pure Swift: https://forums.swift.org/t/what-s-next-for-foundation/61939.
  • Non-copyable types allow you to mark value types with ~Copyable, which prevents structs from being copied. You can also mark functions as consuming, which prevents the value from being used after a consuming method is called.
  • Better C++ support.
  • Custom actor synchronization.
Notes
  • When possible, prefer structured concurrency over unstructured. Structured means things like async let and taskGroup, where unstructured are plain Task { ... } or Task.detached { ... }
  • In other words, it’s better to do async let x = doSomething() instead of let x = Task { await doSomething() }
  • Structured tasks are implicitly cancelled when they go out of scope. Unstructured tasks must be cancelled explicitly with cancel.
  • Cancellation is a race. Cancelling tasks just sets the isCancelled flag to true, which means that code will still execute if the task is cancelled too late.
  • Instead of returning a partial result, you can throw a cancellation error by calling try Task.checkCancellation()
  • 8:00 resume

SwiftUI

Xcode

New technologies