Stewart Lynch Newsletter 2025-33


Stewart Lynch News
2025-33

Please pass on the subscription link to others in your sphere so I can broaden my reach.
https://stewartlynch.kit.com

RichNotes Editor Series

Over the last three weeks, I released a three part series on Attributed Strings in SwiftUI. We built a rich text editor that allows users to apply bold, italic, underline, strikethrough, and color to their text. We also added a menu for changing font size and text alignment, along with a custom keyboard toolbar to streamline the editing experience.

The series persists notes using SwiftData, which gave me the opportunity to introduce some of its features along with a few of its quirks.

You can find them all though this playlist link: https://tinyurl.com/y2czzkcw

If you are experimenting with building your own rich text editor in SwiftUI, you might find this repository from Andrew Cowley, a valuable reference.
https://github.com/disc0infern0/iosRichTextEditor

Andrew reached out to me to say he was inspired by the series and wanted to use my code but add several alternative approaches that simplify state management and reduce code duplication. He suggested using formatting tools that are are driven by a clean enum-based toggle system, toolbar controls that lean on native SwiftUI APIs, and a custom color picker that replaces the default macOS picker with something far more intuitive and polished. I was only too glad to encourage him to do so. I think it’s great whenever anyone can build on my simple teaching examples.

The project also demonstrates a practical way to keep toolbar highlights in sync with the current selection by reading selection.attributes directly, avoiding the need for container probing. It includes notes on edge cases, known limitations with combined font and style attributes, and groundwork for future features like saving and restoring cursor positions. If you’re looking for real-world patterns or inspiration for your own editor, this repo is a solid place to explore.

Upcoming Videos

I have two more full length videos planned before the end of the year and before my final newsletter of the year.

These will be the last two videos for now on new and improved APIs introduced for iOS 26 as in the new year I will going back to creating a few more videos in my Deeper Understanding of SwiftUI series.

This video will introduce you to subtle but powerful improvements to SwiftUI Lists and Labels introduced in iOS 26. I’ll walk you through the new one-liner modifiers, show you how to group data cleanly with dictionary initializers, and add some polished touches like toolbar background visibility and alphabet side indexing.

This video will show how to take full control of your SwiftUI WebViews by injecting custom HTTP headers. Whether you’re passing authentication tokens, API keys, or tracking identifiers, you’ll learn how to create a reusable WebViewHview that makes handling headers simple and secure.

Code placeholders and Editable Template Tokens in Xcode

Forgive me for this next rather geeky section, but I found this to be very interesting and I am always looking for ways to improve my starter project code. I can appreciate that this might not be for everyone.

You probably already know that you can insert code placeholders in your Xcode project. This is particularly useful when you are creating code snippets. I have an entire video on this topic. It dates back to January, 2020, but the content is still relevant.

A code snippet is formed using the <#Placholder Text#> syntax. When you have a snippet in your project that has a placeholder, and you invoke the snippet, when you tab into the placeholder it become replaceable text. This is what you see when you use Xcode's code completion feature.

For example, if you want to get the basic format for a Switch statement, you can just start typing switch and then hit the tab key after selecting the Xcode code snippet and it will expand to provide you with the code with 4 placeholders. One for the value, one for a single case pattern and two for your code blocks. Tabbing will highlight each of the placeholders in your tint color and typing will replace the placeholder with whatever you type.

If you are interested in more about this, I recommend you check out my video.

video preview

The problem with these placeholders is that if you do not replace the placeholder with compilable code, your app will not build.

What I didn't know however was that there is another placeholder format that I was completely unaware of.

I discovered this when I was working through the Modern Persistence series using SQLiteData, on the Point•Free web site https://www.pointfree.co/ I will be talking more about SQLiteData in a future video. I am still working through the series and using it to build out a new app idea I have.

In their sample code, they use a lot of placeholders as well, but their placeholders were entirely different than the ones I was using. Their placeholders included code and the views in the starter projects compiled just fine. They were not using snippet here.
It turns out that these are editable template tokens generated inside code files.

What These Tokens Are

These comment blocks are interactive placeholders that Xcode inserts into generated SwiftUI files.

They mark spots where Xcode wants you to fill in something. They behave like the placeholders.

They are not runtime code and they never ship in your build. They exist only in the editor.

Why They Exist

Apple uses them in SwiftUI templates so Xcode can offer:

  • Quick editing popovers
  • Inline pickers (for example, system images, colors, layouts)
  • Easy tab navigation when creating a file
  • Structured editing (like when choosing a preview device)

They are basically the SwiftUI version of placeholders used in Interface Builder templates.

You see this every time you create a new SwiftUI file. The Text View with "Hello, World" is one of these tokens.

It is not until you tap on Hello world, it becomes selected and highlighted in your accent color (likely blue). If you tap enter on your keyboard, it will use the placeholder text that was provided. If you start typing it will replace the text with whatever you type.

If you want to create placeholders like this in your own code files, the syntax is

Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)

Anything between the /*@START_MENU_TOKEN@*/ and /*@END_MENU_TOKEN@*/ is what becomes the placeholder.

You may wonder, why would I do that, when I could have just as easily typed:

Text(<#"Hello, World"#>)

Well that would not compile because the placeholder is including the quotation marks and the Snippet placeholder will not compile, whereas the same placeholder in a menu token will..

This is especially interesting for me because I want to share starter code with others and when they load the view, I want to make sure that it compiles without error. You cannot do this with simple placeholders or menu tokens without an additional argument that will allow you to specify a string for display of the placeholder, but behind the scenes, you can use code that will compile but never been seen by user.

Take a look at the following code. With normal snippet placeholders, this would not compile because all you are allowed are strings for the placeholder text.

What you can do is specify both a placeholder for a menu token as well as other compilable code or variables.

You still bookend your token with the same tags as before, but you also add a new argument to the token that is the placeholder for display purposes.
/*@PLACEHOLDER=placeholderString@*/

This is followed by the hidden compilable code that you want and it can be as simple as a variable or constant as a binding.

compilableCode

/*@START_MENU_TOKEN@*//*@PLACEHOLDER=placeholderString@*/compilableCode/*@END_MENU_TOKEN@*/

So, for example, the first token above is:
/*@START_MENU_TOKEN@*//*@PLACEHOLDER=someStateVar@*/observedVar/*@END_MENU_TOKEN@*/

It is the hidden observedVar that is a valid variable name that will compile without error.

The entire line of code is written like this where the token becomes just part of the complete line of code
@State private var /*@START_MENU_TOKEN@*//*@PLACEHOLDER=someStateVar@*/observedVar/*@END_MENU_TOKEN@*/ = false

The entire view is written like this:

My Other Stuff

Channel Listing App

A Searchable Mac app containing a list of all of my YouTube videos including the ability to watch them in the app and download starter and completed source code

Free on Gumroad

CustomGPT

A custom ChatGPT that has indexed the transcripts of my videos.
Add to your ChatGPT Sidebar

Smile4Me Course

The course is now Free to download from: https://stewartlynch.github.io/Smile4Me-Course-Content/

Affiliate Links

BigMountain Studio Books 

Mark Moeykens is a master at creating SwiftUI reference books. I have purchased every one of these books and refer to them all the time.

Use this link and we both will benefit

https://www.bigmountainstudio.com/a/77jt8

600 1st Ave, Ste 330 PMB 92768, Seattle, WA 98104-2246
Unsubscribe · Preferences

Stewart Lynch

Join over 23,000 YouTube subcribers who are mastering Swift and SwiftUI.Level up your iOS development skills with concise tutorials and professional development tips delivered straight to your inbox. Subscribe now for exclusive discounts, insider insights, and curated highlights from my 350+ YouTube tutorials.

Read more from Stewart Lynch

Stewart Lynch News2026 - 2 Subscribe to my YouTube Channel Please pass on the subscription link to others in your sphere so I can broaden my reach.https://stewartlynch.kit.com Swift Rockies 2026 I am really excited to announce that I will be speaking at Swift Rockies this summer in Calgary, Alberta, Canada. Swift Rockies is a practitioner-focused, community-driven Swift & iOS conference that brings together experienced iOS engineers and mobile developers for two days of deep technical talks,...

Stewart Lynch News2026 - 1 Subscribe to my YouTube Channel Please pass on the subscription link to others in your sphere so I can broaden my reach.https://stewartlynch.kit.com Happy New Year! I hope all of you had a great couple of weeks enjoying the holiday season and spending time with family and friends. I know I did, and I’m looking forward to the new year. You may notice that the avatar I use for my YouTube channel, which is supposed to resemble me, looks a little different. I use...

Stewart Lynch News2025-34 Subscribe to my YouTube Channel Please pass on the subscription link to others in your sphere so I can broaden my reach.https://stewartlynch.kit.com Recent Videos Since my last newsletter, I released two more videos. Both have been very well received and the view counts have been right up there with my most popular videos so you might want to check them out. List and label improvements This video introduced you to subtle but powerful improvements to SwiftUI Lists and...