Created
February 17, 2015 22:27
-
-
Save KarlNosworthy/a30ad37d7d0e850db731 to your computer and use it in GitHub Desktop.
An attributed string extension which provides a new method to simply find and make links out of specified strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension NSMutableAttributedString { | |
public func setAsLink(textToFind:String, linkURL:String) -> Bool { | |
let foundRange = self.mutableString.rangeOfString(textToFind) | |
if foundRange.location != NSNotFound { | |
self.addAttribute(NSLinkAttributeName, value: linkURL, range: foundRange) | |
return true | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment