11
Swift Range的NSRange?
问题:我在使用使用Range的Swift String时,NSAttributedString需要一个NSRange 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) } }) 产生以下错误: 错误:“范围”不可转换为“ NSRange” attributedString.addAttribute(NSForegroundColorAttributeName,值:NSColor.redColor(),范围:substringRange)