How does NSServicesMenuRequester work with writing tools?
Asked on 2024-07-29
1 search
NSServicesMenuRequester is a protocol that allows the system to read contents from a view and write contents back to the view. When working with writing tools, you need to ensure that your text view adopts this protocol. Here’s how it works:
-
Adopt the Protocol: Make sure your text view adopts the
NSServicesMenuRequesterprotocol. This allows the system to interact with the text view for reading and writing content. -
Override Methods: Override the
validRequestor(forSendType:returnType:)method inNSResponder. This method helps determine if your text view can handle specific types of content. -
Implement Write Selection Method: Implement at least the
writeSelection(to:type:)method inNSServicesMenuRequester. If your view is an editable text view, also implement thereadSelection(from:type:)method to handle rewritten text sent back to the text view. -
Context Menu Integration: As long as a context menu is added to the view, the writing tools menu item will be available automatically. This integration allows your app to be available to various services and shortcuts.
By following these steps, you can enable writing tools in your app, making it easier for users to proofread, rewrite, or transform text within your text views.
For more detailed information, you can refer to the session Get started with Writing Tools.

Squeeze the most out of Apple Pencil
New in iOS 18, iPadOS 18, and visionOS 2, the PencilKit tool picker gains the ability to have completely custom tools, with custom attributes. Learn how to express your custom drawing experience in the tool picker using the same great tool picking experience available across the system. Discover how to access the new features of the Apple Pencil Pro, including roll angle, the squeeze gesture, and haptic feedback.

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.
