SwiftのNSTextViewから選択した文字列を取得する方法は?SwiftのNSTextViewから選択した文字列を取得するには?
// create a range of selected text
let range = mainTextField.selectedRange()
// this works but I need a plain string not an attributed string
let str = mainTextField.textStorage?.attributedSubstring(from: range)
たぶん私は、私は完全な文字列を取得し、それに範囲を適用する中間ステップを追加する必要がありますか?
これは動作するはずです::
let str = mainTextField.text.substring(with: range)
について編集何
ます。http:// stackoverflowの。 com/questions/14024124/get-selection-highlighted-text-string -from-nstextview-objective-c –
Miteshありがとう、私はObjective-CではなくSwiftでプログラミングしています。 – Cue