问题: NSAttributedString需要一个NSRange,而我正在使用一个使用范围的Swift字符串
let text = "Long paragraph saying something goes here!"
let textRange = text.startIndex..<text.endIndex
let attributedString = NSMutableAttributedString(string: text)
text.enumerateSubstringsInRange(textRange, options: NSStringEnumerationOptions.ByWords, { (substring, substringRange, enclosingRange, stop) -> () in
if (substring == "saying") {
attributedString.addAttribute(NSForegroundColorAttributeName, value: NSColor.redColor(), range: substringRange)
}
})
产生以下错误:
错误:'Range'不能转换为'NSRange' attributedString。addAttribute(NSForegroundColorAttributeName,值:NSColor.redColor(),范围:substringRange)