Configuring Writing Tools in SwiftUI
Although most of the configuration options for Writing Tools require UIKit, SwiftUI does offer a writingToolsBehavior view modifier. You can use this view modifier on Text, TextField, and TextEditor views.
To see this in action, open the CoverCraft app from the starter folder and select the CoverLetterView.
Right now, you’ll see that the writingToolsBehavior view modifier is commented out. By default, a SwiftUI TextEditor view offers the complete Writing Tools experience, so this line is not needed.
TextEditor(text: $coverLetterText)
.writingToolsBehavior(WritingToolsBehavior.complete)
Remove the comment characters to reinstate this line. Now, let’s experiment with changing it.
The WritingToolsBehavior choices are:
- automatic: the system decides which Writing Tools experience to present, including disabling the tools, based on context.
- complete: the full in-line experience.
- disabled: Writing Tools will not appear.
- limited: shows only the overlay panel.
When building and running in the Catalyst simulator, the only option that makes a visible difference is setting the behavior to .disabled. Notice that after we do this and build and run, the Writing Tools option no longer appears in the context menu. If you have a device running iOS or iPadOS 18.1 or later, try each option to see how they compare.
In each case, the system only provides the requested behavior “if possible” according to the Apple Developer documentation, so there’s no guarantee that Writing Tools will display as expected.