Cleaner type syntax

Optional any and some types

Swift 6.4 removes the need for extra parentheses when making an any existential or some opaque type optional.

Before Swift 6.4

In Swift 6.3 and earlier, the optional marker had to apply to a parenthesized any or some type:

let error: (any Error)?

protocol Vehicle {}

struct Garage {
    var vehicle: (some Vehicle)?
}

Without the parentheses, the compiler produced a syntax error.

Swift 6.4

The same optional types can now be written directly:

let error: any Error?

protocol Vehicle {}

struct Garage {
    var vehicle: some Vehicle?
}

This is a syntax improvement only. The optional still wraps the complete existential or opaque type; the meaning of the type has not changed.

Reference