来自Swift Range的NSRange?
问题:当我使用使用Range的Swift String时,NSAttributedString接受NSRange
let text = "Long paragraph saying something goes here!"let textRange = text.startIndex..<text.endIndexlet 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'aligolsString.addAttribute(NSForegroundColorAttributeName,value:NSColor.redColor(),range:substringRange)