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、value:NSColor.redColor()、range:substringRange)