Skip to content

Instantly share code, notes, and snippets.

@EfraimB
Last active December 20, 2017 14:21
Show Gist options
  • Save EfraimB/b7605f4f2aea3c2615be691dcddd87a2 to your computer and use it in GitHub Desktop.
Save EfraimB/b7605f4f2aea3c2615be691dcddd87a2 to your computer and use it in GitHub Desktop.
extension NSAttributedString {
func replacing(placeholder:String, with valueString:String) -> NSAttributedString {
if let range = self.string.range(of:placeholder) {
let nsRange = NSRange(range,in:valueString)
let mutableText = NSMutableAttributedString(attributedString: self)
mutableText.replaceCharacters(in: nsRange, with: valueString)
return mutableText as NSAttributedString
}
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment