Wednesday, November 11, 2026
HomeProgrammingWhat’s New in Swift 6.4?

What’s New in Swift 6.4?


Apple shipped Swift 6.4 alongside Xcode 27, and it’s one other a type of releases that’s simple to underestimate at a look. Nothing right here is as flashy as macros or strict concurrency had been, however a handful of small adjustments make day-to-day Swift noticeably much less annoying to put in writing, plus some actual concurrency ergonomics and a standardized construct system, make the improve value it.

Under is a rundown of the adjustments value understanding about, with hyperlinks to the discharge notes and proposals if you wish to go deeper. Just a few subjects — Swift Testing, detailed concurrency adjustments, and library adjustments — solely get a fast tour right here. Devoted articles on these subjects are coming in a while Kodeco.

On this article, every part’s grouped into three buckets:

  • Ergonomics and Syntax Enhancements consists of updates to Swift syntax and compiler habits that make the language simpler to make use of and extra expressive.
  • Concurrency focuses on enhancements to Swift’s concurrency mannequin and async lifecycle administration.
  • Library Updates particulars updates to Swift’s normal library and different core libraries like Basis, XCTest, and Swift Construct.

Use the Obtain Supplies button on the high or backside of this text to obtain the pattern venture. The Starter folder consists of the code earlier than Swift 6.4, and the Remaining folder consists of the code for Swift 6.4. Be sure that to make use of Xcode 26 when utilizing the Starter venture, whereas utilizing Xcode 27 for the Remaining venture. This helps to see the variations within the code and the way Swift 6.4 improves the language and its options. For every subject, the pattern venture features a Swift file with code snippets that present the brand new options and enhancements. You may run the code snippets in a playground, or preview them within the canvas to see how they work in apply.

Ergonomics and Syntax Enhancements

anyAppleOS

@out there and #out there have allow you to gate code by platform since Swift 2.0. The annoying half has all the time been that “Apple platform” isn’t one key phrase — it’s 5. Final yr, for instance, Apple launched a brand new design language referred to as Liquid Glass, and it shipped on each Apple platform. As a part of that, Apple added many new APIs to SwiftUI and UIKit that can assist you undertake this new design language. If you wish to use it in your code, it’s good to gate it by platform model. Up till Swift 6.4, supporting it meant spelling out each platform by hand:


extension View {
  @out there(iOS 26, macOS 26, tvOS 26, watchOS 26, visionOS 26, *)
  func glassCard() -> some View {
    padding()
      .glassEffect(.common, in: .rect(cornerRadius: 16))
  }

  @ViewBuilder
  func adaptiveCard() -> some View {
    if #out there(iOS 26, macOS 26, tvOS 26, watchOS 26, *) {
      glassCard()
    } else {
      padding().background(.ultraThinMaterial, in: .rect(cornerRadius: 16))
    }
  }
}

Swift 6.4 launched a brand new anyAppleOS key phrase that collapses all that into one:


extension View {
  @out there(anyAppleOS 26, *)
  func glassCard() -> some View {
    padding()
      .glassEffect(.common, in: .rect(cornerRadius: 16))
  }

  @ViewBuilder
  func adaptiveCard() -> some View {
    if #out there(anyAppleOS 26, *) {
      glassCard()
    } else {
      padding().background(.ultraThinMaterial, in: .rect(cornerRadius: 16))
    }
  }
}

anyAppleOS means “any Apple platform” so now you can gate code for all Apple platforms with a single key phrase. You may as well mix it with current @out there to exclude a selected platform or customise the supply additional:


// 1
@out there(anyAppleOS 26, iOS 25, *)
func myAwesomeMethod() { ... }

// 2
@out there(anyAppleOS 26, *)
@out there(macOS, unavailable)
func myOtherAwesomeMethod() { ... }
  1. Right here, myAwesomeMethod() is obtainable on all platforms ranging from model 26 apart from iOS, the place it’s out there from model 25.
  2. Right here, myOtherAwesomeMethod() is obtainable on all platforms ranging from model 26, apart from macOS, the place it’s unavailable.

As you possibly can see, anyAppleOS is a small change that makes your code cleaner and simpler to learn. It additionally reduces the chance of by chance forgetting to incorporate a platform in your availability checks.

Smarter memberwise inits

Swift comes with many compiler-generated conveniences. One of the helpful has all the time been the memberwise initializer for structs. Should you don’t write your individual initializer, Swift robotically generates one for you that takes parameters for every saved property within the struct.


struct Session {
  var userID: String
  var token: String

  // generated memberwise initializer:
  // init(userID: String, token: String) {}
}

That is nice, however you possibly can run into bother you probably have a non-public property with a default worth. Swift nonetheless generates a memberwise initializer that features the non-public property, however this time, the initializer itself is non-public. This implies you possibly can’t name it from exterior the struct, which might result in confusion and frustration.


struct Session {
  var userID: String
  var token: String
  non-public var retryCount: Int = 0

  // generated memberwise initializer:
  // non-public init(userID: String, token: String, retryCount: Int) {}
}

In Swift 6.4, non-public properties with default values at the moment are excluded from the generated initializer:


struct Session {
  var userID: String
  var token: String
  non-public var retryCount: Int = 0

  // generated memberwise initializer:
  // init(userID: String, token: String) {}
}

As proven above, the generated initializer excludes the non-public property retryCount, which makes the initializer’s entry degree inside.

Warning management by way of @diagnose

So far, warning management largely meant reaching for compiler flags like -warnings-as-errors or -suppress-warnings. These work, however they’re a blunt instrument — they hit the entire module, not the one operate for which you’re making an attempt to make an exception.

@diagnose fixes that by letting you dial in warning habits proper on the declaration that wants it. Let’s say you could have the next code in your app — a easy credential supervisor that shops a token on disk:


// 1
class CredentialManager {
  // 2
  func storeToken(token: String) { 
    // Saves the token on a file
  }
}

// 3
func signinUser(username: String, password: String) {
  // signal within the consumer and fetch the token
  credentialManager.storeToken(token: token)
}
  1. CredentialManager is a straightforward class that manages consumer credentials.
  2. storeToken saves the token to a file, which isn’t safe and may be accessed by malicious actors.
  3. signinUser shops the token fetched from the backend upon profitable sign-in.

Later, you study Keychain and determine to deprecate storeToken in favor of a safer implementation:


class CredentialManager {
  @out there(*, deprecated)
  func storeToken(token: String) { ... }

  func securelyStoreToken(token: String) {
    // Saves the token in Keychain
  }
}

Now should you attempt to compile with -warnings-as-errors, the decision to storeToken in signinUser will fail the construct.

Screenshot of an error message in Xcode showing that the call to storeToken is deprecated and shown as an error

You may repair it by altering the decision to securelyStoreToken, however possibly you don’t have time to try this proper now. You merely need an exception for this one operate. Earlier than Swift 6.4, you wanted to take away -warnings-as-errors from the construct settings, which might cease each warning within the module from being handled as an error. This isn’t superb.

With @diagnose, now you possibly can add the deprecation diagnostic for this one operate:


@diagnose(DeprecatedDeclaration, as: ignored, cause: "Required extra testing")
func signinUser(username: String, password: String) {
  // signal within the consumer and fetch the token
  credentialManager.storeToken(token: token)
}

Now the remainder of the code nonetheless treats warnings as errors, and you may take your time to correctly repair and check this code later. Should you’d fairly downgrade the diagnostic to a warning as an alternative of dropping it, swap in as: warning as an alternative of as: ignored.

Let’s now take a look at a number of the concurrency enhancements in Swift 6.4.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments