what is~ Copyable, what use cases for it

Generated on 1/28/2025

1 search

The Copyable protocol in Swift is a new feature that describes the ability for a type to be automatically copied. By default, Swift assumes that you want the ability to copy types because it is generally easier to work with copyable types. This means that every type in Swift tries to automatically conform to Copyable, and every generic parameter, protocol, and associated type automatically requires the concrete type to conform to Copyable.

However, there are situations where copying can make your code error-prone. For example, in scenarios like modeling a bank transfer, where running a transfer twice could be costly, it might be better to use non-copyable types to prevent such errors. Non-copyable types are useful for improving program correctness by expressing unique ownership, which is particularly important in cases like managing unique system resources.

For more detailed information, you can refer to the session Consume noncopyable types in Swift (00:00:50) where the concept of copying and non-copyable types is discussed.

What’s new in App Intents

What’s new in App Intents

Learn about improvements and all-new features with App Intents, and discover how this framework can help you expose your app’s functionality to Siri, Spotlight, Shortcuts, and more. We’ll show you how to make your entities more meaningful to the platform with the Transferable API, File Representations, new IntentFile APIs, and Spotlight Indexing, opening up powerful functionality in Siri and the Shortcuts app. Empower your intents to take people deep into your app with URL Representable Entities. Explore new techniques to model your entities and intents with new APIs for error handling and union values.

Consume noncopyable types in Swift

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.

What’s new in Swift

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.

Explore Swift performance

Explore Swift performance

Discover how Swift balances abstraction and performance. Learn what elements of performance to consider and how the Swift optimizer affects them. Explore the different features of Swift and how they’re implemented to further understand the tradeoffs available that can impact performance.