I'm using attributed text
like this:
let formated = textAnhorig.formatHyperlink(text: "click HERE and HERE", link: www.test.com, linkStart: 6, linkEnd: 9)
detailText.attributedText = formated
Using this function:
func formatHyperlink(text: String, link: String, linkStart: Int, linkEnd: Int) {
let attributed = NSMutableAttributedString(string: text)
let url = URL(string: link)
}
Problem is, I want to have two (or more) links in the text (The second HERE). But I can't call the function a second time. Do I need to add multiple arguments, like this:
let formated = textAnhorig.formatHyperlink(text: "click HERE and HERE", link: www.test.com, linkStart: 6, linkEnd: 9, link2: www.test2.com, linkStart: 15, linkEnd18)
There's goto be a better more dynamic way right?
UPDATE Got a suggestion to send the links as dictionaries in an array, but I don't know how to unpack it:
var dict1 = ["link": "www.test.com", "start": 0, "end": 10] as [String : Any]
var dict1 = ["link": "www.test2.com", "start": 22, "end": 66] as [String : Any]
var array = [dict1, dict2]
for i in array {
let url = URL(string: array[i["link"]])
attributed.setAttributes([.link: url], range: NSMakeRange(array[i["start"]], array[i["end"]]))
}