Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
Reflection in Swift: How Mirror works
Reflection in Swift allows us to use the Mirror API to inspect and manipulate arbitrary values at runtime. Even though Swift puts a lot of emphasis on static typing, we can get the flexibility to gain more control over types than you might expect. I've been planning to explore the ...
Creating an App Update Notifier using Combine and async/await
An app update-notifier promotes a new app update to your users. Using a notifier will get better adoption rates with several benefits, like dropping old APIs and better conversion rates. In this article, I'll demonstrate how to create your update-notifier without using any remote configuration. The latest update will be ...
Composition vs. Inheritance: code architecture solutions explained in Swift
Composition and inheritance are both fundamental programming techniques when working in object-oriented programming languages. You've likely been using both patterns in your code already, even though you might not know what they mean. Over the past ten years, I've often been using inheritance throughout my code. Although using inheritance often ...
Property Wrappers in Swift explained with code examples
Property Wrappers in Swift allow you to extract common logic in a distinct wrapper object. This new technique appeared at WWDC 2019 and first became available in Swift 5. It's a neat addition to the Swift library that allows removing much boilerplate code, which we probably all have written in ...
Async await in Swift explained with code examples
Async await is part of the new structured concurrency changes that arrived in Swift 5.5 during WWDC 2021. Concurrency in Swift means allowing multiple pieces of code to run at the same time. This is a very simplified description, but it should give you an idea already how important concurrency ...
Nonisolated and isolated keywords: Understanding Actor isolation
SE-313 introduced the nonisolated and isolated keywords as part of adding actor isolation control. Actors are a new way of providing synchronization for shared mutable states with the new concurrency framework. If you're new to actors in Swift, I encourage you to read my article Actors in Swift: how to ...
EXC_BAD_ACCESS crash error: Understanding and solving it
Building apps all goes well in the beginning. You're developing an app from scratch; it's stable and runs perfectly fine. After releasing the first version, you get your first insights into crashes, from which one marks an EXC_BAD_ACCESS error. At this point, it's time to start your journey into solving ...
Race condition vs. Data Race: the differences explained
Race conditions and data races are similar but have a few significant differences you should know. Both terms are often used when developing multi-threaded applications and are the root cause for several kinds of exceptions, including the well-known EXC_BAD_ACCESS. By understanding the differences between them, you'll learn how to solve ...
Thread Sanitizer explained: Data Races in Swift
The Thread Sanitizer, also known as TSan, is an LLVM based tool to audit threading issues in your Swift and C language written code. It was first introduced in Xcode 8 and can be a great tool to find less visible bugs in your code, like data races. At WeTransfer, ...
@AppStorage explained and replicated for a better alternative
The @AppStorage Property Wrapper was introduced in SwiftUI to allow easy access to the user defaults. When property wrappers were introduced, many examples used a user defaults wrapper as an example. It's a common use case where you can move boilerplate code into a wrapper. Although the @AppStorage wrapper is ...
How to use throwing properties to catch failures in Swift
Throwing properties allow defining computed properties that throw an error on failure. SE-310 introduced this feature in Swift 5.5 and is part of the async-await concurrency changes allowing async properties to throw errors. By defining throwing computed properties, we better handle unhappy flows without defining methods for simple accessors—the same ...
Unwrap or throw: Exploring solutions in Swift
Unwrap or throw is a scenario in which we want to throw an error if an optional returns a nil value. Techniques like if let or guard statements make this easy to do but often return in quite some boilerplate code. In cases like this, I'm always hoping to find ...