Task Groups in Swift allow you to combine multiple parallel tasks and wait for the result to return when all tasks are finished. They are commonly used for tasks like combining multiple API request responses into a single response object. Read my article about tasks first if you’re new to them, and make sure you’ve …
Engineering goals: How to become a more successful developer
Engineering goals create focus and help you achieve the milestones of becoming a successful developer. You’ll know better what you’ve accomplished in the past months, and make sure that you work on projects with the highest impact. Over the past years, goals helped me successfully release new versions of RocketSim and Stock Analyzer. While I …
SwiftLee 2022: A Year in Review
Another year passed by, and we’re close to getting into 2023. It’s been a year with a single Swift 5.7 release, Xcode 14, new SwiftLee products, and many articles. I always enjoy looking back on the year and realizing what I’ve achieved, hopefully inspiring others for the year to come. More than ever, I’ve been …
OptionSet in Swift explained with code examples
OptionSet in Swift allows you to define a set of options for configurations. It’s the Swift variant of the well-known NS_OPTIONS in Objective-C and it’s used throughout the standard libraries. A set of options is often confused by a set of enum cases, but they’re not the same. While you could create a similar solution …
How to use FormatStyle to restrict TextField input in SwiftUI
A custom FormatStyle can help you control the allowed characters of a SwiftUI TextField. You might want to allow numbers only or a specific set of characters. While you could use a formatter in many cases, it’s good to know there’s a flexible solution using a custom FormatStyle implementation. In my case, I was looking …
Sheets in SwiftUI explained with code examples
Sheets in SwiftUI allow you to present views that partly cover the underlying screen. You can present them using view modifiers that respond to a particular state change, like a boolean or an object. Views that partly cover the underlying screen can be a great way to stay in the context while presenting a new …
@dynamicCallable in Swift explained with code examples
It’s all in the name: @dynamicCallable in Swift allows you to dynamically call methods using an alternative syntax. While it’s primarily syntactic sugar, it can be good to know why it exists and how it can be used. We covered @dynamicMemberLookup earlier, allowing us to express member lookup rules in dynamic languages naturally. @dynamicCallable is …
Binary Targets in Swift Package Manager
Binary Targets in Swift Package Manager (SPM) allow packages to declare xcframework bundles as available targets. The technique is often used to provide access to closed-source libraries and can improve CI performance by reducing time spent on fetching SPM repositories. Both downs and upsides are essential to consider when adding binary targets to your project. …
Result builders in Swift explained with code examples
Result builders in Swift allow you to build up a result using ‘build blocks’ lined up after each other. They were introduced in Swift 5.4 and are available in Xcode 12.5 and up. Formerly known as function builders, you’ve probably already used them quite a bit by building a stack of views in SwiftUI. I …
Getting started with Unit Tests in Swift
Unit tests in programming languages ensure that written code works as expected. Given a particular input, you expect the code to come with a specific output. By testing your code, you’re creating confidence for refactors and releases, as you’ll ensure the code works as expected after running your suite of tests successfully. Many developers do …