Swift
Learn more and get better in Swift using this list of Swift blog posts, tutorials, tips, and tricks.
Ranges in Swift explained with code examples
Ranges in Swift allow us to select parts of Strings, collections, and other types. They're the Swift variant of NSRange which we know from Objective-C, although they're different in usage, as I'll explain in this blog post. Ranges allow us to write elegant Swift code by using the range operator ...
Optimizing your app for Network Reachability
Network Reachability is a vital aspect of apps that use some networking capabilities. Your users won't always have a good internet connection, so optimizing your app for bad networking conditions is essential. We can leverage several techniques to optimize our app accordingly, but it's essential to be aware of common ...
The operation couldn’t be completed: solving errors in Swift
"The operation couldn't be completed" is a common error to receive from Apple's standard SDKs or 3rd party libraries. The errors often come with an error code that doesn't have a description, leaving you behind with unclear directions on solving the issue. I've been running into these errors quite often, ...
Equatable conformance in Swift explained with code examples
Equatable conformance allows you to compare one object with another. Based on whether the objects match, you can perform a specific operation. You can rely on default comparison implementations or custom logic to compare two objects. Many standard types are already comparable, but you must implement protocol conformance for your ...
Detached Tasks in Swift explained with code examples
Detached tasks allow you to create a new top-level task and disconnect from the current structured concurrency context. You could argue that using them results in unstructured concurrency since you're disconnecting potentially relevant tasks. While it sounds terrible to disconnect from structured concurrency, there are still examples of use cases ...
Task Groups in Swift explained with code examples
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 ...
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 ...
@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 ...
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 ...
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 ...
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 ...
Announcing the SwiftLee Talent Collective
Today I'm excited to introduce you to the SwiftLee Talent Collective — an initiative to connect engineers with exciting companies. One of the most frequently asked questions I get relates to how to find a new job or how to make the next career step. I wrote about Swift Jobs: ...