【发布时间】:2017-03-08 07:31:15
【问题描述】:
如何在 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)
也许我必须添加一个中间步骤来获取完整的字符串,然后在其上应用范围?
【问题讨论】:
-
谢谢 Mitesh,不过我是用 Swift 编程而不是 Objective-C。
标签: swift xcode cocoa macos-sierra nstextview