Swift: 如何从 NSTextField 连续发送一个动作

Swift: How to continuously send an action from a NSTextField

我有一个 NSTextField 并且想在用户更改值时发送一个动作。我在 Interface Builder 中检查了 "Continuous"(它可以与 NSSlider 一起工作),但是 NSTextField 仅在我不关注它时才发送他的动作。如何从 NSTextField 连续发送一个动作(使用 Swift)?

将文本字段的委托设置为 class,它应该接收操作并实现

func controlTextDidChange(_ obj: NSNotification)

This method is invoked when text in a control such as a text field or form changes. The control posts a NSControlTextDidChangeNotification notification, and if the control’s delegate implements this method, it is automatically registered to receive the notification. Use the key @"NSFieldEditor" to obtain the field editor from the userInfo dictionary of the notification object.