にこのコードを確認のNSWindowControllerのサブクラス内にある:現在選択されているテキスト
@objc func textViewDidChangeSelection(_ notification: Notification) {
// Show the previous (not current) selection range
if let stuff = notification.userInfo {
var i = 0
for (key, value) in stuff {
print("\(i) key=\(key) value=\(value)")
i += 1
}
}
}
override func windowWillLoad() {
NotificationCenter.default.addObserver(self,
selector: #selector(self.textViewDidChangeSelection(_:)),
name: NSTextView.didChangeSelectionNotification,
object: nil)
}
通知内の2つの辞書エントリの値は、以前のテキストの選択に対応する範囲を提供します。通知が発行されたときの現在のテキスト選択を知るには?
また、NSTextFieldが複数ある場合、どの通知が開始されたかを知る方法は? – Aarhus88