[フレーム]
BT

InfoQ Software Architects' Newsletter

A monthly overview of things you need to know as an architect or aspiring architect.

View an example

We protect your privacy.

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Unlock the full InfoQ experience

Unlock the full InfoQ experience by logging in! Stay updated with your favorite authors and topics, engage with content, and download exclusive resources.

Log In
or

Don't have an InfoQ account?

Register
  • Stay updated on topics and peers that matter to youReceive instant alerts on the latest insights and trends.
  • Quickly access free resources for continuous learningMinibooks, videos with transcripts, and training materials.
  • Save articles and read at anytimeBookmark articles to read whenever youre ready.

Topics

Choose your language

InfoQ Homepage News Swift 6.1 Enhances Concurrency, Introduces Package Traits, and More

Swift 6.1 Enhances Concurrency, Introduces Package Traits, and More

May 04, 2025 2 min read

Write for InfoQ

Feed your curiosity. Help 550k+ global
senior developers
each month stay ahead.
Get in touch
Listen to this article - 0:00
Audio ready to play
0:00
0:00

Swift 6.1, included in Xcode 16.3, introduces several improvements to the language and the Swift Package Manager, including type-wide global actor inference control, support for trailing commas in lists, package traits for conditionally exposing features based on the platform, and enhancements to Swift Testing.

Prior to Swift 6.1, the nonisolated keyword could be used to indicate that a property or function was safe to call from any concurrent context. In Swift 6.1, this support extends to types and extensions. There are two main use cases: when working with an actor-isolated protocol that includes methods which don’t require isolation, or when opting out of actor isolation in a protocol for which isolation is globally inferred.

For the first case, consider the following code:

@MainActor
protocol IsolatedStruct {
 // mutable state requiring isolation
}
extension IsolatedStruct: CustomStringConvertible, Equatable {
 // properties and methods not requiring isolation
 var description: String {
 ...
 }
 static func ==(lhs: S, rhs: S) -> Bool {
 ...
 }
}

The methods in the extension do not need to be actor-isolated, but the Swift 6 compiler still requires them to run on @MainActor unless they are explicitly marked nonisolated. In Swift 6.1, you can now write nonisolated extension IsolatedStruct:... to achieve the same effect.

For the second case, without diving into the complex rules governing global actor inference, it’s enough to say that if you want to override the compiler’s automatic decision about which global actor a type is assigned to, perhaps due to a property wrapper or another hard-to-trace dependency, you can mark the entire type as nonisolated.

A minor but welcome change to the language syntax is the ability to use trailing commas in tuples, parameter and argument lists, generic parameter lists, closure capture lists, and string interpolations, in addition to the previously supported collection literals. This will be especially useful in plugins and macros, as generating comma-separated lists no longer requires a special case for the final element.

Package traits are a new Swift Package Manager feature used to define a set of traits a package offers. This makes it possible to express conditional compilation and optional dependencies, making it easier to offer different APIs and features when used in specific environments, such as Embedded Swift and WebAssembly.

Speaking of Swift Testing, the new TestScoping protocol lets you define custom test traits that modify the scope in which a test executes. This can be useful, for example, to bind a local value to a mocked resource. Moreover, Swift Testing now provides updated versions of the #expect(throws:) and #require(throws:) macros which return the error they caught.

Swift 6.1 includes many more improvements than we can cover here, so be sure to check out the official Swift evolution documentation for the full details.

As mentioned, Swift 6.1 is included in Xcode 16.3. It can also be installed on Linux using swiftly and on Windows using WinGet or Scoop.

About the Author

Sergio De Simone

Show moreShow less

Rate this Article

Adoption
Style

This content is in the Mobile topic

Related Topics:

Related Content

The InfoQ Newsletter

A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

We protect your privacy.

BT

AltStyle によって変換されたページ (->オリジナル) /