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 : // 유래. co.kr/questions/14024124/get-selection-highlighted-text-string -from-nstextview-objective-c –
Mitesh에게 감사드립니다. 그러나 Objective-C가 아닌 Swift에서 프로그래밍하고 있습니다. – Cue