View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • 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.

    Capítulos

    • 0:00 - Introduction
    • 3:42 - Native text views
    • 7:03 - Controlling behavior
    • 8:23 - Protecting ranges
    • 9:03 - Custom text views
    • 11:44 - Next steps

    Recursos

    • Forum: UI Frameworks
    • WKWebView
    • AppKit
    • UIKit
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC23

    • What’s new with text and text interactions

    WWDC22

    • What's new in TextKit and text views

    WWDC21

    • Meet TextKit 2
    • What's new in AppKit

    WWDC19

    • Modernizing Your UI for iOS 13
  • Buscar neste vídeo...
    • 5:28 - Text view delegate methods for Writing Tools

      func textViewWritingToolsWillBegin(_ textView: UITextView) {
          // Take necessary steps to prepare. For example, disable iCloud sync.
      }
      
      func textViewWritingToolsDidEnd(_ textView: UITextView) {
          // Take necessary steps to recover. For example, reenable iCloud sync.
      }
      
      if !textView.isWritingToolsActive {
          // Do work that needs to be avoided when Writing Tools is interacting with text view
          // For example, in the textViewDidChange callback, app may want to avoid certain things
             when Writing Tools is active
      }
    • 7:11 - Opt-out of the full experience

      textView.writingToolsBehavior = .limited
      
      textView.writingToolsBehavior = .none
    • 7:31 - Specify accepted text formats

      textView.writingToolsAllowedInputOptions = [.plainText]
      
      textView.writingToolsAllowedInputOptions = [.plainText, .richText, .table]
    • 7:55 - WKWebView

      // For `WKWebView`, the `default` behavior is equivalent to `.limited`
      
      extension WKWebViewConfiguration {
          @available(iOS 18.0, *)
          open var writingToolsBehavior: UIWritingToolsBehavior { get set }
      }
      
      extension WKWebViewConfiguration {
          @available(macOS 15.0, *)
          open var writingToolsBehavior: NSWritingToolsBehavior { get set }
      }
      
      extension WKWebView {
          /// @discussion If the Writing Tools behavior on the configuration is `.limited`, this will always be `false`.
          @available(iOS 18.0, macOS 15.0, *)
          open var isWritingToolsActive: Bool { get }
      }
    • 8:48 - Protecting ranges

      // Returned `NSRange`s are relative to the substring of the textView’s textStorage from `enclosingRange`
      func textView(_ textView: UITextView, writingToolsIgnoredRangesIn
              enclosingRange: NSRange) -> [NSRange] {
          let text = textView.textStorage.attributedSubstring(from: enclosingRange)
          return rangesInappropriateForWritingTools(in: text)
      }
    • 9:58 - Indicate your text view supports editing

      protocol UITextInput {
          @available(iOS 18.0, macOS 15.0, *)
          optional var isEditable: Bool { get }
      }
    • 10:58 - Simple view that supports Copy

      class CustomTextView: NSView, NSServicesMenuRequestor {
          required init?(coder: NSCoder) {
              super.init(coder: coder)
              
              self.menu = NSMenu()
              self.menu?.addItem(NSMenuItem(title: "Custom Text View", action: nil,
                  keyEquivalent: ""))
              self.menu?.addItem(NSMenuItem(title: "Copy", action: #selector(copy(_:)), 
                  keyEquivalent: ""))
          }
        
          override func draw(_ dirtyRect: NSRect) {
              super.draw(dirtyRect)
              
              // Custom text drawing code...
          }
      }
    • 11:05 - View extension to support Writing Tools

      class CustomTextView: NSView, NSServicesMenuRequestor {
          override func validRequestor(forSendType sendType: NSPasteboard.PasteboardType?, 
                                       returnType: NSPasteboard.PasteboardType?) -> Any? {
              if sendType == .string || sendType == .rtf {
                  return self
              }
              return super.validRequestor(forSendType: sendType, returnType: returnType)
          }
          
          nonisolated func writeSelection(to pboard: NSPasteboard,
                                          types: [NSPasteboard.PasteboardType]) -> Bool {
              // Write plain text and/or rich text to pasteboard
              return true
          }
      
          // Implement readSelection(from pboard: NSPasteboard)
             as well for editable view
      }

Developer Footer

  • Vídeos
  • WWDC24
  • Get started with Writing Tools
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines