UITextView – can't set underline or strikethrough attributes on text?
Your underline style is invalid. Change this line:
let underlineAttribute = [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle]
to this:
let underlineAttribute = [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]
Result: