Dynamic Theming in SwiftUI Apps

A robust theme system is important to consider when creating an app. It allows all your colours, fonts and assets to belong in one place so they can be easily updated. It can also be extended to allow the user to change the look and feel of your app. It can also help you as a developer to stick to consist styles if you don’t have a designer on hand....

November 29, 2024 · 5 min

Making a Lightweight Dependency Container in Swift

Dependency injection is a powerful design pattern in Swift that helps to improve code flexibility, modularity and testability. At its simplest, it involves providing an object with all the resources it needs to function from an external source rather than creating them internally within the object. This approach improves flexibility by making it easier to replace or mock different dependencies without changing the object itself. We ‘inject’ different object in....

November 15, 2024 · 6 min

Designing and Implementing a Daily Streak System in Swift

Daily streaks are a great way to boost engagement and help to keep users coming back to your app. If you’re unsure of what a streak is, think of apps such as Duolingo. They track how many days in a row a user has opened your app or completed an action such as finishing a quiz. There’s something about watching the number go up every day and trying not to break the streak that really helps with user retention....

November 13, 2024 · 9 min

How to Trigger an Action When a SwiftUI Toggle Changes

Sometimes we may need to call an action every time a toggle changes instead of relying purely on a state property to keep our toggle up to date. Luckily this is easy to do. An action can be called when a toggle is updated (or any control that takes in a binding, such as a slider) and a state property will be used to display the state in the control....

August 11, 2022 · 2 min

How to Add a Search Bar to a List in SwiftUI

SwiftUI now has the ability to add a search bar in iOS 15. This is done through the searchable() modifier which adds a search bar under your navigation view automatically. To get started, we need our data and a state property to keep track of the search term. @State private var searchTerm = "" private let cats = ["Persian", "Tabby", "Ragdoll", "Sphynx", "Maine Coon"] Next, we need a computed property to filter our data depending on the search term....

June 8, 2022 · 2 min