Swift - does controlTextDidChange work with NSTextView?

I have one text field and one textView. The controlTextDidChange method responds to changes in the text field. But he does not respond to text changes.

class AppDelegate: NSObject,NSApplicationDelegate,NSTextFieldDelegate,NSTextViewDelegate {
    func applicationWillFinishLaunching(notification:NSNotification) {
        /* delegates */
        textField.delegate = self
        textView.delegate = self    
    }

    override func controlTextDidChange(notification:NSNotification?) {
        if notification?.object as? NSTextField == textField {
            print("good")
        }
        else if notification?.object as? NSTextView == textView {
            print("nope")
        }
    }
}

I am running Xcode 7.2.1 under Yosemite. Am I doing something wrong?

+4
source share
1 answer

controlTextDidChange:is a class method NSControlthat inherits NSTextField, but not NSTextView:

enter image description here

Because of this, NSTextView instances cannot receive the above callback.

I think that instead of <<255> you should use textDidChange::

func textDidChange(notification: NSNotification) {
  if notification.object == textView {
    print("good")
  }
}
+5
source

All Articles