What is Property Wrapper?

Asked on 01/21/2025

1 search

A property wrapper in Swift is a feature that encapsulates logic for managing stored values. It allows you to intercept the calls to read and write a property, implementing reusable logic that can be applied to a property with a simple annotation. This feature is particularly useful for building expressive, type-safe APIs and eliminating boilerplate code in applications. For example, the argument property wrapper from the Swift ArgumentParser package can be applied to a property to designate that it stores the value of a command line argument. This allows for more concise and maintainable code by abstracting common patterns into reusable components.

For more details, you can refer to the session A Swift Tour: Explore Swift’s features and design (23:13).