how to adopt writing tools
Asked on 2024-07-30
1 search
To adopt Writing Tools in your app, you can follow these steps:
-
Native Text Views: If you are using
UITextView,NSTextView, orWKWebView, Writing Tools will work automatically in a supported environment. Ensure that your text views use TSC2 for the full Writing Tools experience. If using TSC1, the experience will be limited to showing rewritten results in a panel. For more details, refer to the Get started with Writing Tools session. -
Custom Text Views: If you have a custom text view, you can still integrate Writing Tools. Implement the
NSServicesMenuRequesterprotocol to allow the system to read and write contents from the view. Override thevalidRequesterForSendTypemethod and implement thewriteSelectionmethod. This will enable Writing Tools in the context menu for your custom text view. For more details, refer to the Custom text views chapter. -
Controlling Behavior: You can control the behavior of Writing Tools by adopting new delegate methods. For example, you can specify ranges of text to ignore, such as code blocks or quoted content, by using the new delegate methods in
UITextFieldDelegateandNSTextViewDelegate. For more details, refer to the Controlling behavior chapter. -
Protecting Ranges: To protect certain ranges of text from being rewritten, implement the new delegate methods to return the ranges you want to ignore. For
WKWebView, elements likeblockquoteandprewill be ignored automatically. For more details, refer to the Protecting ranges chapter. -
Next Steps: After integrating Writing Tools, try it out with your app. In most cases, it will work automatically. Adopt the new delegate methods to control your app's state during a Writing Tools session. For more details, refer to the Next steps chapter.
For a comprehensive guide, you can watch the full session Get started with Writing Tools.

Get started with Writing Tools
Learn how Writing Tools help users proofread, rewrite, and transform text in your app. Get the details on how Writing Tools interact with your app so users can refine what they have written in any text view. Understand how text is retrieved and processed, and how to support Writing Tools in custom text views.

What’s new in AppKit
Discover the latest advances in Mac app development. Get an overview of the new features in macOS Sequoia, and how to adopt them in your app. Explore new ways to integrate your existing code with SwiftUI. Learn about the improvements made to numerous AppKit controls, like toolbars, menus, text input, and more.
