how to adopt writing tools

Asked on 2024-07-30

1 search

To adopt Writing Tools in your app, you can follow these steps:

  1. Native Text Views: If you are using UITextView, NSTextView, or WKWebView, 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.

  2. Custom Text Views: If you have a custom text view, you can still integrate Writing Tools. Implement the NSServicesMenuRequester protocol to allow the system to read and write contents from the view. Override the validRequesterForSendType method and implement the writeSelection method. This will enable Writing Tools in the context menu for your custom text view. For more details, refer to the Custom text views chapter.

  3. 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 UITextFieldDelegate and NSTextViewDelegate. For more details, refer to the Controlling behavior chapter.

  4. 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 like blockquote and pre will be ignored automatically. For more details, refer to the Protecting ranges chapter.

  5. 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.