Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
AnyObject, Any, and any: When to use which?
AnyObject and Any got a new option any as introduced in SE-355, making it harder for us developers to know the differences. Each option has its use cases and pitfalls regarding when not to use them. Any and AnyObject are special types in Swift, used for type erasure, and don't ...
How to use the #available attribute in Swift
Marking pieces of code as available or unavailable per platform or version is required in the ever-changing landscape of app development. When a new Swift version or platform version arrives, we'd like to adapt to it as soon as possible. Without throwing away support for older versions we can make ...
Self-documenting code in Swift to increase readability
Self-documenting code helps explain a piece of code to other developers on a project without the need for actual documentation. The readability of our code is an essential part of making code easier to understand for developers that didn't write the code. You could argue that it's even crucial for ...
Tasks in Swift explained with code examples
Tasks in Swift are part of the concurrency framework introduced at WWDC 2021. A task allows us to create a concurrent environment from a non-concurrent method, calling methods using async/await. When working with tasks for the first time, you might recognize familiarities between dispatch queues and tasks. Both allow dispatching ...
Guard statements in Swift explained with code examples
Guard statements in Swift allow us to implement checks into our code that prevents the current scope from continuing. When writing code, we often have certain required conditions before continuing a method. An example can be unwrapping an optional input field before submitting a form. Required conditions can be either ...
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 ...
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 ...