NSAttributedString attribute in CoreData

I have an NSAttributedString attribute in an entity marked as Transformable with the transformer set to NSSecureUnarchiveFromDataTransformerName.

I have a Transformer defined as:

class AttributedStringTransformer: NSSecureUnarchiveFromDataTransformer {



    override class func allowsReverseTransformation() -> Bool {

        return true

    }



    override class func transformedValueClass() -> AnyClass {

        return NSAttributedString.self

    }



    override class var allowedTopLevelClasses: [AnyClass] {

        return [NSAttributedString.self]

    }



    override func transformedValue(_ value: Any?) -> Any? {

        guard let data = value as? Data else {

            fatalError("Wrong data type: value must be a Data object; received \(type(of: value))")

        }

        return super.transformedValue(data)

    }



    override func reverseTransformedValue(_ value: Any?) -> Any? {

        guard let string = value as? NSAttributedString else {

            fatalError("Wrong data type: value must be a Reminder object; received \(type(of: value))")

        }

        return super.reverseTransformedValue(string)

    }

}



extension AttributedStringTransformer {

    /// 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: AttributedStringTransformer.self))



    /// Registers the value transformer with `ValueTransformer`.

    public static func register() {

        let transformer = AttributedStringTransformer()

        ValueTransformer.setValueTransformer(transformer, forName: name)

    }

}

The transformer is registered on launch.

When I launch the app with the string initialised to an empty attributed string the app fails right away with:

CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x6000005679c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

2021-08-12 08:53:30.390456+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

2021-08-12 08:53:30.391637+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

2021-08-12 08:53:30.458505+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

2021-08-12 08:53:30.459614+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

2021-08-12 08:53:30.459835+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)

2021-08-12 08:53:30.471535+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x60000056d8c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x60000056d8c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)

I have put break points on the transformer, but it never hits them.

The behaviour of the app gives me the feeling that this is a bug in CoreData, but I can't pin it down.

Can someone please suggest what might be wrong. I am using Xcode 13.0 beta 5 (it failed on beta 4 as well).

NSAttributedString attribute in CoreData
 
 
Q