来自Swift Range的NSRange? [英] NSRange from Swift Range?
本文介绍了来自Swift Range的NSRange?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题: NSAttributedString在我使用使用范围的Swift字符串时使用NSRange
Problem: NSAttributedString takes an NSRange while I'm using a Swift String that uses Range
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'
attributionString.addAttribute( NSForegroundColorAttributeName,value:NSColor.redColor(),range:substringRange)
error: 'Range' is not convertible to 'NSRange' attributedString.addAttribute(NSForegroundColorAttributeName, value: NSColor.redColor(), range: substringRange)
推荐答案
这篇关于来自Swift Range的NSRange?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文