Recent articles

Jump to a random post

Deciding between a computed property and a function in Swift

Published on: April 26, 2024

In Swift, we can use computed properties to derive a value from other values defined on the same object. Being able to do this is super convenient because it means that we don’t have to manually make sure that we update derived properties every time one of the “source” values changed. We’ll just recompute the property every time it’s accessed! If you prefer to learn from video, here's the companion video for this blog post: This is very similar to having a function that takes no arguments and returns a value: struct User { let givenName: String let familyName: String...

Read more...

if case let in Swift explained

Published on: April 26, 2024

In Swift, we can use the case keyword in multiple places. Most commonly, a case is used in switched but since you’re here, you might have seen a case in combination with an if statement. In this post, we’ll explore different places where we can use the case keyword to perform something called pattern matching in Swift. Pattern matching is a powerful feature of Swift that allows us to perform highly elegant checks to see if a given type matches a certain value. In this post, we’ll explore a specific kind of pattern matching in Swift; the if case let...

Read more...

How Enterprise level CI/CD with AppCircle helps you scale

Published on: April 25, 2024

As teams grow and companies mature you’ll often find that it gets harder and harder to manage processes that seemed to be so simple before. When I worked in startups one of my favorite things was how quick the feedback cycle was on pretty much everything I did. When someone designed a new feature we could build that and ship it on Testflight as quick as a couple of hours. If the designer liked the way the implemented feature works they would sign off and off to App Review we’d go. Usually everybody in the company would be on the...

Read more...

What are lazy vars in Swift?

Published on: April 23, 2024

Sometimes when you’re programming you have some properties that are pretty expensive to compute so you want to make sure that you don’t perform any work that you don’t absolutely must perform. For example, you might have the following two criteria for your property: The property should be computed once The property should be computed only when I need it If these two criteria sound like what you’re looking for, then lazy vars are for you. A lazy variable is defined as follows: class ExamResultsAnalyser { let allResults: [ExamResult] lazy var averageGrade: Float = { return allResults.reduce(0.0, { total, result...

Read more...

Deciding between a for loop or forEach in swift

Published on: April 23, 2024

Swift offers multiple ways to iterate over a collection of items. In this post we’ll compare a normal for loop to calling forEach on a collection. Both for x in collection and collection.forEach { x in } allow you to iterate over elements in a collection called collection. But what are their differences? Does one outperform the other? Is one better than the other? We’ll find out in this post. Using a regular for loop I’ve written about for loops in Swift before so if you want an in-depth look, take a look at this post. A regular for loop...

Read more...

Dispatching to the Main thread with MainActor in Swift

Published on: April 23, 2024

Swift 5.5 introduced loads of new concurrency related features. One of these features is the MainActor annotation that we can apply to classes, functions, and properties. In this post you’ll learn several techniques that you can use to dispatch your code to the main thread from within Swift Concurrency’s tasks or by applying the main actor annotation. If you’d like to take a deep dive into learning how you can figure out whether your code runs on the main actor I highly recommend reading this post which explores Swift Concurrency’s isolation features. Alternatively, if you’re interested in a deep dive...

Read more...

How to use experimental Swift versions and features in Xcode?

Published on: April 18, 2024

If you’re keen on reading about what’s new in Swift or learn about all the cool things that are coming up, you’re probably following several folks in the iOS community that keep track and tell you about all the new things. But what if you read about an upcoming Swift feature that you’d like to try out? Do you have to wait for it to become available in a new Xcode release? Sometimes the answer is Yes, you’ll have to wait. But more often than not a Swift evolution proposal will have a header that looks a bit like this:...

Read more...

Actor reentrancy in Swift explained

Published on: April 11, 2024

When you start learning about actors in Swift, you’ll find that explanations will always contain something along the lines of “Actors protect shared mutable state by making sure the actor only does one thing at a time”. As a single sentence summary of actors, this is great but it misses an important nuance. While it’s true that actors do only one thing at a time, they don’t always execute function calls atomically. In this post, we’ll explore the following: Exploring what actor reentrancy is Understanding why async functions in actors can be problematic Generally speaking, you’ll use actors for objects...

Read more...

Building a backend-driven paywall with RevenueCat

Published on: April 4, 2024

On of app development’s largest downsides (in my opinion) is that it’s frustratingly hard for developers to quickly iterate on an app’s core features due to the App Review process which can take anywhere between a few hours to a few days. As a result of this process, developers either need to ship their apps with A/B testing built in if they want to test multiple variations of a feature, they can iterate more slowly or they can opt to build a so-called backend-driven UI. A backend-driven UI is a user interface that’s drawn by fetching information about the UI...

Read more...

Using closures for dependencies instead of protocols

Published on: April 2, 2024

It’s common for developers to leverage protocols as a means to model and abstract dependencies. Usually this works perfectly well and there’s really no reason to try and pretend that there’s any issue with this approach that warrants an immediate switch to something else. However, protocols are not the only way that we can model dependencies. Often, you’ll have a protocol that holds a handful of methods and properties that dependents might need to access. Sometimes, your protocol is injected into multiple dependents and they don’t all need access to all properties that you’ve added to your protocol. Also, when...

Read more...