Skip to content

Instantly share code, notes, and snippets.

@EzimetYusup
Created October 12, 2016 19:41
Show Gist options
  • Save EzimetYusup/67c63460c09510cb706ac5ae67ed2a19 to your computer and use it in GitHub Desktop.
Save EzimetYusup/67c63460c09510cb706ac5ae67ed2a19 to your computer and use it in GitHub Desktop.
extension NSMutableAttributedString for to find the range of String
extension NSMutableAttributedString {
public func getRangeOfString(textToFind:String)->NSRange{
let foundRange = self.mutableString.rangeOfString(textToFind)
return foundRange
}
}
//example of use
let attributedString = NSMutableAttributedString(string:"Love GitHub")
let foundRange = attributedString.getRangeOfString("love")
if foundRange.location != NSNotFound {
//add attribute
// attributedString.addAttributes(myAttribute,foundRange)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment