Underlined AttributedString produces errors in Swift 4

Viewed 465

I have discovered that my App crashes whenever I add an attribute that underlines the text in an NSAttributedString. The documentation of NSAttributedStringKey.underlineStyle clearly states that the value should be a constant from NSUnderlineStyle. By simply putting the following code in a playground you instantly see an error.

import UIKit

let underlinedAttributes: [NSAttributedStringKey: Any] = [
    NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle
]

let attributedString = NSAttributedString(string: "Test", attributes: underlinedAttributes)

Error: [_SwiftValue encodeWithEncoder:] unrecognized selector sent to instance 0x6040000451...

Is this a bug or is there a solution?

0 Answers
Related