Hi everyone,
I also get similar Xcode errors with Xcode 16 when running the app on a device but not with the simulator:
fault: Declared Objective-C type ".NSAttributedString" for attribute named title is not valid>
CoreData: fault: Declared Objective-C type ".NSAttributedString" for attribute named title is not valid
CoreData: Declared Objective-C type ".NSAttributedString" for attribute named title is not valid
The attribute title is declared with: @NSManaged public var title: NSAttributedString
In the model, it is configured with:
type: Transformable
Optional, Transient, etc. all unchecked
Transformer: DescriptionValueTransformer
Custom class: NSAttributedString
Module: Current Product Module
The ValueTransformer is declared with:
ValueTransformer.setValueTransformer(DescriptionValueTransformer(), forName: .descriptionToDataTransformer)
And here is the DescriptionValueTransformer class :
@objc(DescriptionValueTransformer)
public class DescriptionValueTransformer: NSSecureUnarchiveFromDataTransformer {
public override class func allowsReverseTransformation() -> Bool {
return true
}
public override class func transformedValueClass() -> AnyClass {
return NSAttributedString.self
}
public override class var allowedTopLevelClasses: [AnyClass] {
return super.allowedTopLevelClasses + [NSAttributedString.self]
}
public override func transformedValue(_ value: Any?) -> Any? {
guard let data = value as? Data else {
preconditionFailure("Wrong data type: value must be a Data object; received \(type(of: value))")
}
return super.transformedValue(data)
}
public override func reverseTransformedValue(_ value: Any?) -> Any? {
guard let description = value as? NSAttributedString else {
preconditionFailure("Wrong data type: value must be a NSAttributedString object; received \(type(of: value))")
}
return super.reverseTransformedValue(description)
}
}
extension NSValueTransformerName {
public static let descriptionToDataTransformer = NSValueTransformerName(rawValue: "DescriptionValueTransformer")
}
Any help would be very appreciated.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: