Last active
October 17, 2017 21:16
-
-
Save mminer/3f8faa5cad8330c83609268221f65f78 to your computer and use it in GitHub Desktop.
Extension to NSMutableAttributedString that creates a link.
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 Cocoa | |
extension NSMutableAttributedString { | |
/// Makes the specified text a clickable hyperlink. | |
func hyperlink(text: String, with url: URL, additionalAttributes: [NSAttributedStringKey: Any] = [:]) { | |
var attributes = additionalAttributes | |
attributes[.link] = url.absoluteString | |
let range = (string as NSString).range(of: text) | |
addAttributes(attributes, range: range) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment