NSRange from Swift Range?

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) } }) … Read more

NSRange to Range

How can I convert NSRange to Range<String.Index> in Swift? I want to use the following UITextFieldDelegate method: func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool { textField.text.stringByReplacingCharactersInRange(???, withString: string) 16 Answers 16