Search code examples
macoscocoanstextviewappkit

NSTextView's insertText method is deprecated in OS X v10.11. What is the replacement?


I saw in the AppKit API Reference that the insertText method is deprecated in OS X v10.11. What am I supposed to use as a replacement?


Solution

  • The documentation says

    - (void)insertText:(id)aString
    

    This method is the means by which text typed by the user enters an NSTextView. See the NSInputManager class and NSTextInput protocol specifications for more information. ...

    In NSTextInput there is a note:

    IMPORTANT

    NSTextInput protocol is slated for deprecation. Please use NSTextInputClient protocol, introduced in OS X v10.5, as described in NSTextInputClient Protocol Reference.

    In NSTextInputClient protocol there is a method

    - (void)insertText:(id)aString
      replacementRange:(NSRange)replacementRange
    

    This seems to be the appropriate replacement