Learn Something New
A series of one-off tutorials designed to help expand your knowledge of Swift, SwiftUI, and more. Sometimes they will be practical and contain knowledge you can apply straight away, other times we'll just explore fun quirks and curiosities of coding for Apple platforms, but you'll definitely learn something new!
Swift
Tutorials about the Swift language itself.
1. Using Codable with protocols
It's easy to encode an array of objects that have the same type, but how can you handle an array of objects with a different type? In this tutorial I'll show you exactly how to do it with a simple and effective approach.
2. The pitfalls of string bridging
Swift's strings are designed to work flawlessly with languages around the world, but sometimes – just sometimes – you need to be careful using them. Let's explore why…
Did you know it's possible for two things to be considered equal even when they aren't the same? Let's look at how hashing works in Swift, how we can tweak it for performance, what problems it can cause, and most importantly how to make sure those problems never strike your code.
Everyone knows the print()
function, not least because it's often our first port of call when debugging. But printing in Swift can be so much more powerful! Let's dig in…
5. Actors and actor reentrancy
Swift's actors are an incredibly powerful way to schedule work safely, but they have a catch: actors allow reentrant code, which can cause surprising problems. Let's explore how actors work, and how reentrancy can catch you out…
6. Managing your app's memory high water mark
Swift loves value types because they are fast and light, but so much of our work builds on older APIs powered by UIKit and other Objective-C APIs, where it's easy to hit memory problems. Let's look at a smart solution, and how it also impacts modern frameworks like SwiftData…
Optionals are a power feature in Swift, but they can be a little clumsy to work with. In this article I'll introduce four ways to make optionality easier to handle, including ditching them entirely.
Dictionaries provide simple and fast key-value storage, but they have some superpowers that can really help clean up your code. Let's take a look at them now…
In a world of huge projects and countless frameworks from Apple and third parties, how can Swift refer to every type uniquely? The answer is name mangling, and if you're careful it's useful in your code too.
Xcode
Tutorials to help you make better use of Xcode.
1. Personalizing your Xcode header
We make new files in Xcode all the time, but if you spend just a few minutes you can customize the comments that are automatically placed at the start to make them suit you much better.
Although using print()
calls is often the first thing we reach for when diagnosing a problem, let me walk you through a handful of smarter ways to debug your code with breakpoints.
We already looked at advanced uses of breakpoints, but now I want to introduce you to their close friend: watchpoints. These tell you where a value changed, even when you don't know!