Nil Coalescing Newsletter - April 2025
Hi there,
It’s the end of April, and here in Central Otago, autumn is in full swing. This month has been busy with local harvest festivals, and the landscape is filled with beautiful shades of gold and red. Between enjoying the season, we've also been hard at work, and I’m excited to share what we've been up to.
Swift Gems book update
Earlier this month, I released a major update to my book Swift Gems. "Swift Gems" has been out for almost a year now, and it’s been wonderful hearing from so many readers who found it useful, even after years of working with Swift.
One of the things readers often mentioned was how much they appreciated the format — short, self-contained tips that you can read independently without needing to follow a strict order. With that in mind, I wanted to make sure the book continues to grow alongside Swift itself. This latest update adds a fresh collection of new tips, covering the latest language advancements in Swift 6.0 and 6.1, along with new examples and refinements based on features introduced in earlier versions of Swift.
As always, the update is completely free for all existing readers. If you’ve already purchased the book, you can now read the updated version online or download it from the book page. You can also view the release notes for a detailed list of what’s new and changed. If you haven't accessed your copy for a while and your browser cookie expired, you can easily refresh your access link by providing the email address associated with your purchase in the request access form.
If you don’t have a copy yet and are looking for a collection of practical, focused Swift tips to sharpen your skills and keep up with the latest language developments, Swift Gems is available on our website. The purchase includes lifetime access to all future updates, with more additions planned as Swift evolves.
LexiMorph: Letter Game release
After being busy working on my books and client projects over the past few months, I felt like building something just for fun. I wanted to create a small, self-contained app that would be simple and satisfying to use, and that’s how LexiMorph: Letter Game came to life.
LexiMorph is a Mac word game where you are given one big word and challenged to create as many smaller words as possible from its letters. You can use each letter only as many times as it appears in the original word, and every word must be at least two letters long. The idea is simple, but it quickly becomes engaging once you get into it, making it a nice way to take a short break or unwind.
I designed the game primarily using SwiftUI, with a few parts built with AppKit where needed. It's a fully native app with a clean interface that keeps the focus on the gameplay. LexiMorph works entirely offline, does not require an account, and uses a curated dictionary based on the Collins Scrabble Words list to check word validity.
If you enjoy word games and want something light to play on your Mac, you can find LexiMorph on the Mac App Store.
Screenshot of LexiMorph highlighting available letters and dimming used letters during word input

Tech Learnings
For LexiMorph, I needed strict validation on the input field. Players should only be able to type letters that exist in the base word, and only as many times as they are available. Special characters, spaces, and excess letters should be rejected immediately.
At first, I tried intercepting changes through the binding in SwiftUI, but this approach was glitchy, invalid input would still briefly appear before being removed. I also tried using SwiftUI’s TextField(_:value:formatter:)
initializer, passing a custom formatter, but SwiftUI didn't apply it for input validation at all.
To solve this properly, I built a custom InputFormatter
and used an NSTextField
wrapped in NSViewRepresentable
. Assigning the formatter directly to the NSTextField
allowed me to reject invalid characters before they appeared, keeping the input clean.
Here’s a simplified version of how the text field is set up:
struct InputTextField: NSViewRepresentable {
@Binding var text: String
@Environment(GameState.self) var gameState
let formatter = InputFormatter()
func makeNSView(context: Context) -> NSTextField {
let textField = NSTextField()
formatter.gameState = gameState
textField.formatter = formatter
// configure appearance
return textField
}
func updateNSView(
_ nsView: NSTextField, context: Context
) {
if nsView.stringValue != text {
nsView.stringValue = text
}
}
}
Validation happens inside a custom Formatter
subclass, shortened here to show the main idea:
class InputFormatter: Formatter {
var gameState: GameState?
override func isPartialStringValid(
_ partialString: String,
newEditingString newString:
AutoreleasingUnsafeMutablePointer<NSString?>?,
errorDescription error:
AutoreleasingUnsafeMutablePointer<NSString?>?
) -> Bool {
// Validate input against base word letter availability
if validateString(partialString) {
return true
} else {
return false
}
}
private func validateString(_ string: String) -> Bool {
// Check if input uses only available letters
return true
}
}
When a player tries to type an invalid letter, the input is immediately blocked, and an alert message appears underneath the text field explaining why it was rejected.
Screenshot showing LexiMorph preventing invalid input from being entered into the text field

Blog
"Swift Gems" book update: new techniques from recent and past Swift releases
"Swift Gems" by Natalia Panferova has been updated with tips from Swift 6, along with new techniques based on earlier Swift versions, covering optionals, noncopyable types, async programming, and more.
Create a fully custom About window for a Mac app in SwiftUI
Design a custom About window for your SwiftUI macOS app with a personalized layout, detailed app information, and a styled background that fits your app’s look and feel.
Automatic image accessibility labels from localized strings in SwiftUI
SwiftUI uses a localized string matching the image name as the accessibility label, without needing to apply the accessibilityLabel() modifier.
Ways to customize text color in SwiftUI
SwiftUI offers several methods to change the color of text, including foregroundStyle() and tint() modifiers, AttributedString attributes, and the textRenderer() API for advanced styling.
Text concatenation vs Text interpolation in SwiftUI
Combining multiple SwiftUI Text views into a single text with the + operator to apply different styles can cause localization issues, making text interpolation the preferred technique for accurate translations.
Method dispatch mechanisms in Swift: static and dynamic dispatch
Dive into how static and dynamic dispatch work in Swift, how they affect performance, and how to control method resolution to write faster, more efficient code.
Discounts
Every month, I share exclusive, limited-time offers on my books with email newsletter subscribers. Sign up so you don’t miss future newsletter issues and can take advantage of upcoming discounts!