7

So, in my awakeFromNib method of a UILabel subclass I have:

let termsArg = "Terms & Conditions" 
self.linkText = termsArg

let exampleText = String(format:"By signing up you agree to our %@ and Privacy Policy", termsArg)

let underlinedAttributedString = NSMutableAttributedString(string: exampleText) 
self.linkTextRange = (exampleText as NSString).range(of: termsArg)

let attributes = [NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle] 
underlinedAttributedString.addAttributes(attributes, range: self.linkTextRange)

self.attributedText = underlinedAttributedString

But, the line where I add these attributes ends up causing a hard crash where only the following is spit out to the console:

-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00005e510

I'm wondering what's gone wrong, because it appears that I've done everything right.

vadian
  • 274,689
  • 30
  • 353
  • 361
horseshoe7
  • 2,745
  • 2
  • 35
  • 49
  • Although the solution is the same, I'm dealing with a UILabel and not a UITextView. So don't delete this question. – horseshoe7 Nov 30 '17 at 16:34
  • 1
    Your question has not been deleted and it is the same issue. Both questions are asking about attributed strings and the underline attribute. Just because one is using the attributed string for a text view and one is using it for a label is irrelevant. It's the same basic question with the same issue and same error. – rmaddy Nov 30 '17 at 16:39
  • ... and yet I couldn't find it after searching because I thought it was a problem with UILabel and thus wrote a new question. It's the same issue, we agree on that. It's a different path to get there, and so by not deleting it, it will help others find the solution quicker. Thanks. – horseshoe7 Nov 30 '17 at 16:51
  • 8
    @horseshoe7, Just change with this let attributes = [NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle.rawValue] – iPhoneDev Jan 24 '18 at 15:15

0 Answers0