Defining Transformer for NSAttributedString

Coredata used to save attributed strings, but now requires a secure coding transformer. I have tried the code below, but it fails claiming
Code Block
This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it

The transformer has been registered and the attributes given the name 'AttributedStringToDataTransformer'

Any suggestions as to what is wrong?

Here's the code:
Code Block
class AttributedStringToDataTransformer: ValueTransformer {
    override func transformedValue(_ value: Any?) -> Any? {
        let boxedData = try! NSKeyedArchiver.archivedData(withRootObject: value!, requiringSecureCoding: true)
        return boxedData
  }
    override func reverseTransformedValue(_ value: Any?) -> Any? {
        let typedBlob = value as! Data
        let data = try! NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSAttributedString.self], from: typedBlob)
        return (data as! NSAttributedString)
    }
}
extension AttributedStringToDataTransformer {
    /// The name of the transformer. This is the name used to register the transformer using `ValueTransformer.setValueTrandformer(_"forName:)`.
    static let name = NSValueTransformerName(rawValue: String(describing: AttributedStringToDataTransformer.self))
    /// Registers the value transformer with `ValueTransformer`.
    public static func register() {        ValueTransformer.setValueTransformer(AttributedStringToDataTransformer(), forName: name)
    }
}

I think the issue might be because I am using custom attributes. It is ok if none are present.
Defining Transformer for NSAttributedString
 
 
Q