NEW BOOK! SwiftUI Fundamentals: The essential guide to SwiftUI core concepts and APIs. Learn more ...NEW BOOK! SwiftUI Fundamentals:Master SwiftUI core concepts and APIs. Learn more...

Nil Coalescing Newsletter - March 2025

Hi there,

Welcome to the third issue of this newsletter, which now reaches over 2,600 subscribers 😲 I'm so grateful for all your ongoing support and interest in what we're doing here at Nil Coalescing. It's amazing to see this community continue to grow!

I've got some exciting updates to share this month. First, many of you asked for an online version of the newsletter, and I'm happy to announce it's now live! If you've missed any previous issues, you can find them on the Newsletter archive page on our website. I'll publish each new issue there shortly after sending it out via email, but the special book discounts I share each month will remain exclusive to email subscribers.

Second, I've begun revisiting some of my older blog posts to ensure they are accurate and up-to-date with the latest APIs. It's quite a big project, as I've been blogging for over five years now and have more than 100 posts to check! I'll gradually work through them whenever I find a spare moment. This month, several posts received minor updates, so I kept their original publish dates. However, a couple of articles, like Detecting the focused window on macOS and Custom environment values in SwiftUI, needed complete rewrites due to significant API changes. For those, I've refreshed the publish dates and treated them as new posts.

Lastly, I'm excited to share that I've recently appeared as a guest on two podcasts: the EmpowerApps podcast and Dev Conversations. You can find more details in the "Podcasts" section below. If you're curious about other podcasts and talks I've done over the years, check out the Talks, podcasts and videos page on our website.


Podcasts

EmpowerApps Podcast

I had the pleasure of chatting with Leo Dion on the EmpowerApps Podcast about my new book, "SwiftUI Fundamentals". We covered common misconceptions about SwiftUI, practical tips for getting the most out of the framework, and our experiences building apps for iOS and macOS.

Dev Conversations – SwiftToolkit.dev

I also really enjoyed speaking with Natan Rolnik on Dev Conversations, a podcast series from SwiftToolkit.dev. We talked about how I got started in iOS development, my experience working on SwiftUI at Apple, and what it's been like writing technical books. We explored SwiftUI's ongoing evolution and why sharing knowledge with the developer community is so important.


Projects

Alexandra Community House website

This month, I also wanted to share something a bit different - a local community project Matt and I recently completed. Last year, after we moved to Alexandra, a small town in the South Island of New Zealand, we looked for opportunities to use our technical skills to help our new community. We ended up working with Alexandra Community House, a facility hosting various services and organizations supporting people across Central Otago, to build their very first website. Despite their longstanding presence in the community, they'd never had a website before, so it felt like an especially meaningful project.

After many months spent gathering requirements, talking with the different organizations based there, and collaborating closely with the busy team at Community House, we are thrilled that the website is now live.

Our main goal was to create a clear, easy-to-navigate, and accessible site suitable for everyone in the community, including older residents and people who may not own computers and rely exclusively on their mobile phones to access the internet.

On the technical side, we built the site using a fork of Publish, enhanced with additional Swift packages to convert images into multiple media formats (including JXL and AVIF), enabling browsers to select the most efficient format automatically. To keep things streamlined and cost-effective, all media assets are hashed, with the hash appended to each filename, and an asset manifest is generated to map the original filenames to their uploaded CDN URLs. This setup allows us to quickly regenerate the site on-demand using an AWS Lambda function, which references this asset manifest rather than needing to handle local copies of images each time text based content is updated.

Because the website features an events calendar, we set up automatic daily updates at 2 AM local time, using the AWS Lambda function to ensure events always stay current.

To make content management easy for the Community House staff, we built a secure admin portal where they can create, update, or delete events, and add announcement banners. Although the site and admin pages are static, we implemented secure user authentication with cookies through CloudFront JavaScript functions, ensuring only authorized users can access the admin area.

When staff update content through the admin portal, it triggers another Swift-based AWS Lambda function, updating backend data stored as JSON in a private S3 bucket, regenerating necessary pages, and automatically redirecting users back to the updated page.

Overall, our approach focused on minimizing long-term maintenance costs by using serverless cloud functions instead of a traditional server and database. We also avoided relying heavily on client-side JavaScript to ensure the website remains easily indexable by search engines and loads quickly for all users. For interactive functionality, like filtering lists or viewing calendar tabs, we used CSS fragment-based URL targeting, keeping the site simple, fast, and accessible.


Tech Learnings

Using fixedSize() to prevent unnecessary text truncation

I recently ran into a small but frustrating SwiftUI layout issue in one of my apps and thought it might be worth mentioning how I worked around it, in case you encounter something similar.

By default, a SwiftUI Text view doesn't have a line limit, so it naturally wraps onto multiple lines and only truncates when there's genuinely not enough space. However, I've noticed that in slightly complex layouts, text occasionally gets truncated for no obvious reason, even when there's plenty of available space for it to wrap across multiple lines.

I’ve run into this issue a few times, most recently in the settings window of my app EncodeDecode. The text at the bottom of the first Form section was unexpectedly truncated, despite having sufficient vertical space to wrap. The only height constraint applied in this layout is on the entire settings window, and even experimenting with significantly increasing the window's height doesn't resolve the truncation issue.

Settings Form with truncated text at the bottom of the first section

Settings Form with truncated text at the bottom of the first section

In situations like these, I usually rely on the fixedSize(horizontal:vertical:) modifier as a workaround. This modifier instructs SwiftUI to ignore the size proposal in one or both dimensions, allowing the view to display at its ideal size instead. In this specific case, I applied fixedSize(horizontal: false, vertical: true) to the view with truncated text.

AllowedCharsInfo()
    .fixedSize(
        horizontal: false,
        vertical: true
    )

This ensures that the text respects horizontal constraints, so it wraps normally, but disregards the vertical constraint, expanding vertically as needed.

Settings Form with wrapped text at the bottom of the first section

Settings Form with wrapped text at the bottom of the first section

However, it’s important to be cautious with this solution. We need to ensure that the text will have enough vertical space to be fully displayed, especially on platforms that support Dynamic Type, like iOS. To avoid potential issues, it helps to keep the layout flexible, for example by allowing users to scroll when content grows beyond the visible area.


Blog

Adapting images and symbols to Dynamic Type sizes in SwiftUI

Make SF Symbols and custom images adapt to different font sizes while maintaining layout balance, keeping key icons clear, and providing more space for higher-priority content when needed.

Custom environment values in SwiftUI

Learn how to define custom environment values in SwiftUI, eliminate boilerplate with the @Entry macro in Xcode 16, and pass data through the view hierarchy efficiently.

Customizing modal presentation background and color scheme in SwiftUI

Set a custom background, like an image or a translucent material, for SwiftUI sheets, popovers, and full-screen covers, and explicitly control the presentation color scheme.

Designing a custom lazy list in SwiftUI with better performance

Implement a high-performance lazy scrolling list in SwiftUI by efficiently reusing views for smooth scrolling with large datasets.

Detecting the focused window on macOS in SwiftUI

Detect window focus with the appearsActive environment value to adjust UI and handle focus changes.


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!


Subscribe so you don’t miss future issues!

Invalid email address

Unexpected server error

Subscribed!

We take your privacy seriously and will never share your details with third parties.

You can unsubscribe anytime using the link in our emails.

Newsletter RSS feed