What is thus
Generated on 8/3/2024
1 search
What is "type throws" in Swift?
"Type throws" is a new feature introduced in Swift 6 that enhances the error handling system by allowing you to specify the error type along with the throws
keyword. This means that there is no type erasure involved, and the error appears in the catch block with its concrete type. This feature is a generalization of the existing error handling system, where untyped throws are equivalent to type throws with an Any
error type, and a non-throwing function is equivalent to a function with a type throw of the Never
type.
Type throws allows for more precise API contracts and can be particularly useful in constrained environments where untyped throws are cost-prohibitive. It also helps avoid code duplication by allowing functions like map
to be written generically over the failure type, abstracting over both throwing and non-throwing cases.
For more details, you can watch the session What’s new in Swift (24:19).
Relevant Sessions
A Swift Tour: Explore Swift’s features and design
Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.
Bring your app’s core features to users with App Intents
Learn the principles of the App Intents framework, like intents, entities, and queries, and how you can harness them to expose your app’s most important functionality right where people need it most. Find out how to build deep integration between your app and the many system features built on top of App Intents, including Siri, controls and widgets, Apple Pencil, Shortcuts, the Action button, and more. Get tips on how to build your App Intents integrations efficiently to create the best experiences in every surface while still sharing code and core functionality.
What’s new in Swift
Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.
Consume noncopyable types in Swift
Get started with noncopyable types in Swift. Discover what copying means in Swift, when you might want to use a noncopyable type, and how value ownership lets you state your intentions clearly.