0

I am using mutableAttributedString string in textview with attributed link text format. I am getting attributed link for two different attributed link without any space. But I i am adding same text with attributed link type and then getting only one range for two link attributed string.

I am Using Below Code:

func getlinkRange(attributeString: NSAttributedString) -> [MentionStruct] {
        var arr = [DemoStruct]()
        _ =  attributeString.enumerateAttribute(NSLinkAttributeName, in: NSRange.init(location: 0, length: attributeString.length), options: [], using: { (value, range, stop) in
            if let url = value {
                let occurrence = (attributeString.string as NSString).substring(with:range)
                arr.append(MentionStruct(link: url as! String, text: occurrence, range: range))
            }
        })
        return arr
    }

Ex:- @TestingName@TestingName

enter image description here

Thanks In Advance,

Dharma
  • 3,007
  • 3
  • 23
  • 38
BalKrishan Yadav
  • 467
  • 7
  • 21
  • You may want to look for "@" between the occurence found. It's normal behaviour if you print your NSAttributedString with the issue, you'll see it. – Larme Jul 21 '17 at 11:54
  • Not Getting Your Point, I Want to separate both link attributed text from before @.. – BalKrishan Yadav Jul 21 '17 at 12:10
  • Could you print the NSAttributedString for the case when it's not working and show us the value? It works on the Screen shot but not for `@TestingName@TestingName` right? – Larme Jul 21 '17 at 12:11
  • Yes, Its Printing single string ...like below @Testing Name Title@Testing Name Title{ NSFont = " font-family: \".SFUIText\"; font-weight: normal; font-style: normal; font-size: 17.00pt"; NSLink = "connectmention://B898828B-4512-441C-8FD9-87933471F521--1--ed8a784d-c0ef-4ca2-8a70-c493fb8c3c1d"; } – BalKrishan Yadav Jul 21 '17 at 12:15
  • For `@TestingName@TestingName` it should print only one (and that's a normal issue, but you want to modify it). But for `@Testing Name Title@Testing Name Title` it shouldn't I guess. So there may be an issue on how add the links attributes. – Larme Jul 21 '17 at 12:20

0 Answers0