In this Basics article, let’s take a look at a few examples of the various kinds of properties that Swift supports, and what their characteristics are.
This week, let’s take a look at how Swift’s property wrappers work, and explore a few examples of situations in which they could be really useful.
This week, let’s take a look at convenient, but sometimes divisive language feature — computed properties — and how they can let us build really elegant convenience APIs, how to avoid accidentally hiding performance problems when deploying them, and a few different strategies for picking between a computed property and a method.
While there are a number of abstractions that we can create to be able to observe and communicate value changes — Swift comes built-in with a simple, yet powerful way to attach observations to any kind of non-lazy, stored property — appropriately named property observers.
Lazy properties allow you to create certain parts of a Swift type when needed, rather than doing it as part of its initialization process. This can be useful in order to avoid optionals, or to improve performance when certain properties might be expensive to create. This week, let’s take a look at a few ways to define lazy properties in Swift, and how different techniques are useful in different situations.