Unraveling Swift Result Builders

In Swift 5.4, a powerful new feature was introduced that revolutionized how we can work with composable pieces of code: Result Builders. If you’ve written any SwiftUI code, you’ve probably already encountered this feature without realizing it. Result Builders underpin much of the magic that makes SwiftUI’s declarative syntax possible. However, their use isn’t limited to SwiftUI. In this blog post, we’re going to delve into Result Builders, what they are, and how you can use them to build more expressive and powerful APIs....

June 11, 2023 · Mike Gopsill ·  Swift

Examples of Swift Property Wrappers

Swift’s property wrappers are a powerful tool that allows developers to change how properties are stored and manipulated while keeping their interfaces clean and consistent. This post will discuss some practical use cases for property wrappers. Let’s get started! 1. UserDefault Wrapper UserDefaults is a straightforward mechanism to store small amounts of data persistently. We can simplify UserDefaults interactions with a UserDefault property wrapper: @propertyWrapper struct UserDefault<T> { let key: String let defaultValue: T init(_ key: String, defaultValue: T) { self....

June 2, 2023 · Mike Gopsill ·  Swift

Swift Property Wrappers

Property Wrappers were introduced to Swift in 5.1. Initially, they can seem a bit mystifying. However, they’re a powerful tool, helping to streamline your code and make it more expressive. Today, we’ll demystify Property Wrappers and learn how to use them in Swift. What Exactly is a Property Wrapper? Think of a Property Wrapper as a special kind of structure, class, or enumeration that “wraps” around a property in your code....

June 1, 2023 · Mike Gopsill ·  Swift