Movatterモバイル変換


[0]ホーム

URL:


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.

Live Webinar and Q&A: How AI is reshaping connector architecture: From REST APIs to dynamic ingestion (Dec 4, 2025) Save Your Seat

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 HomepageNewsSwift 6 Officially Available

Swift 6 Officially Available

Sep 26, 20243min read

Write for InfoQ

Feed your curiosity.Help 550k+ global
senior developers
each month stay ahead.
Get in touch

The Swift team has officially announced the availability of Swift 6, a new major version of Apple open-source language with focus on low-level and embedded programming, concurrent code safety, new cross-platforms APIs, and extended Linux and Windows support.

InfoQ has already covered several features brought by Swift 6, includingEmbedded Swift, a compilation mode that aims to address the specific constraints of embedded devices and kernel-level code;Swift Testing, a new cross-platform testing framework; and thedata-race free safe mode, aimed at helping developers create concurrent programs free of data races thanks to a new compile-time static detector.

Other major new features in Swift 6 are typed throws, memory ownership extensions for generics, 128 bit integers support, and extended C++ interoperability.

Typed throws enable the specification of the type of errors a function can throw as part of its signature. So, instead of declaring a generic throw clause,

func parseRecord(from string: String) throws -> Record {   // ... }

you can now explicitly declare the error type. This will bring the additional simplification that when you wrap the call to such a function in ado...try...catch block, the type of the error is already known at compile time:

func parseRecord(from string: String) throws(ParseError) -> Record {   // ... }// call site:do {  let record = try parseRecord(from: myString)} catch {  // 'error' has type 'ParseError'}

Interestingly, all Swift 6 functions have a typed throw signature under the hood. Indeed, a function with a non-typedthrows is equivalent to a function throwingAny Error, while a non-typethrows is equivalent tothrows(any Error).

It is important to stress thatthis feature is not meant to replace non-typed throws everywhere.

This feature is useful in generic code that forwards along errors thrown in client code, or in resource-constrained environments that cannot allocate memory, such as in embedded Swift code.

In fact, according to the the authors of the evolution proposal "the existing (untyped) throws remains the better default error-handling mechanism for most Swift code".

The newmemory ownership model has been introduced in Swift 5.9 and Swift 6 brings it a tad further by extending support for generics "move only" types.

The concept of ownership is functional to controlling which piece of code is responsible for a given value to be eventually destroyed. Until Swift 5.9, Swift memory model was not exposed to programmers, as it was the case, e.g., with manual reference counting in Objective-C. Rather, it was encoded in a set of rules that worked pretty well in the general case, but made it harder to get more control on how values were destroyed using the default reference counting algorithm.

Without going into much detail, the memory ownership model exposed in Swift 5.9 is based on the concepts ofborrowing andconsuming, which allows customization of how initializers and functions treat ownership of the arguments they receive and, therefore, modify Swift default assumptions that initializers get the ownership (hence, consume) while functions do not (hence, they borrow).

An integral part of this model is represented by the"non copyable" protocol, which is used for "move only" types, i.e. a type whose values always have a unique ownership and cannot be copied. The implementation of the protocol in Swift 5.9 could not be used with generics, protocols, or existentials, butSwift 6 fills this gap by extending it. Covering the details of~Copyable for generics goes beyond the scope of the present article, so check out the linked Swift Evolution proposal for more details.

Related to the~Copyable protocol, Swift 6 leverages it to extend C++ interop to move-only types. If a C++ class has no copy constructor, Swift assumes it is~Copyable, with the possibility of explicitly ignoring an existing copy constructor using theSWIFT_NONCOPYABLE annotation. In addition, virtual methods, default arguments, and more standard library types such asstd::map andstd::optional are now supported.

Speaking of platform support, Swift 6 can be used now onmore Linux distributions, including Amazon Linux, Debian, Fedora, Red Hat, and Ubuntu, and Windows x86_64 and arm64 architectures. On Linux, theSwift 6 SDK supports building fully statically linked executables with no external dependencies and cross-compiling from other Linux platforms.

There is a lot more to Swift 6 than can be covered here, so do not miss the official announcement for the full details.

About the Author

Sergio De Simone

Show moreShow less

Rate this Article

Adoption
Style

  • Related Editorial

    • Related Sponsor

      Related sponsor icon

      See Boomi AI Agents in action and unlock integration hyperproductivity responsibly. Embedded directly in the platform, Boomi AI Agents empower you to fast-track integrations, optimize workflows, and leverage agentic power across your digital landscape.Learn more.

    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

    [8]ページ先頭

    ©2009-2025 Movatter.jp