Core Data transformable attribute problem in Xcode16

Hi everyone,

Have anybody faced with Core Data issues, trying to migrate the project to Xcode16 beta 4? We are using transformableAttributeType in some entities, with attributeValueClassName = "[String]" and valueTransformerName = "NSSecureUnarchiveFromData". It is working just fine for years, but now I am trying to run the project from Xcode16 and have 2 issues:

  1. in Xcode logs I see warning and error:

CoreData: fault: Declared Objective-C type "[String]" for attribute named alertBarChannels is not valid

CoreData: Declared Objective-C type "[String]" for attribute named alertBarChannels is not valid

  1. periodically the app crashes when we are assigning value to this attribute, with error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'

Once again, in Xcode 15 it works fine, and it was working for years. Cannot find any information about what was changed in the framework... Thank you in advance for any information, which could clarify what is going on.

Were you able to find any solution for this issue? I'm also facing the same issue.

Any update?

I am facing the same issue with transformable attributes with Xcode 16 beta 6

fault: Declared Objective-C type "[Int]" for attribute named .... is not valid
CoreData: fault: Declared Objective-C type "[Int]" for attribute named .... is not valid
CoreData: Declared Objective-C type "[Int]" for attribute named .... is not valid

Finally in Xcode 16 beta 6 I have no warnings and no crashes.

@AGDq interesting, but our 'Declared Objective-C type "[String]" ...' disappear in beta 6...

hi,

downloaded the release version of Xcode 16.0 (16A242d) last night ... and today i ran into this warning.

I will just summarise solution, which works to us (thanks a lot @AGDq ) :

  • combination attributeValueClassName: [String], valueTransformerName: NSSecureUnarchiveFromData does not work now, works combination attributeValueClassName: NSArray, valueTransformerName: NSSecureUnarchiveFromData.

The @NSManaged variable could still be array of strings, like: @NSManaged public internal(set) var routes: [String]?

  • if you use own valueTransformer, like attributeValueClassName: MyLocation. valueTransformerName: LocationValueTransformer, both classes should be marked as @objc(name of class). Without the names there will be warnings in the Xcode log

  • if use set valueTransformerName = "NSSecureUnarchiveFromData", you need to set some class name to attributeValueClassName property, either NSObject, NSArray or own, otherwise the app will periodically crashes. Before it could be empty and it worked as NSObject

Appreciate the answer above does appear to fix the issue, but this isn't really an ideal solution, and doesn't help us understand how we should be using transformers really.

Specifically I feel like there's code smell around type erasure as a solution here, given that we're dealing with Foundation objects.

I ran into the "Declared Objective-C type "[String]" for attribute named..." issue too. The thing that seemed to help was changing the Custom Class from "[String]" to "NSArray<String>". Hope that helps!

So, what is the Apple recommended way in dealing with this? Using a type erased NSArray? @DTS Engineer

I face the same issue CoreData: fault: Declared Objective-C type "[Int]" for attribute named knockedPins is not valid.

knockedPins attribute is Transformable with Custom Class [Int]

what will be the solutions

Experiencing same issue with a custom type. Total joke this is... hours wasted

From my time on Xcode 16.2....with ios18+

As mentioned above there are 2 types of ixes - depends if your 'Transformable' is a 'NSSecureUnarchiveFromData' or a custom one you wrote. for the former things like [String] can be converted to NSArray<NSString> or [String:Any] can convert other NSDictionary etc. (THE 'NS' bits are critical) For your own custom transformers (say you have a class called PermittedTypes' you should have that as an encoding/decoding class and a linked swift file called something like PermittedTypesTransformer.swift IN BOTH classes add the line: @objc('the class name) in the line BEFORE the class declaration. Now in xcdatamoel your custom Transformable should be converted from something like [PermittedTypes] to NSArray<PermittedTypes>

This technique allows you to keep your strong typing on any transformable, unlike the answers above which suggested [String] or [Int] or anything should become NSArray, rather than NSArray<NS{type}> or NSArray<CustomType name>

Same works if you are converting arrays, like [String: Any] becoming NSDictionary or [[String:Any]] becoming NSArray<NSDictionary>

Here is my answer again, with proper punctuation this time :)

From my time on Xcode 16.2....with ios18+

As mentioned above there are 2 types of fixes - depends if your 'Transformable' is a 'NSSecureUnarchiveFromData' or a custom one you wrote.

For the former things like [String] can be converted to NSArray<NSString> or [String:Any] can convert to NSDictionary etc. (THE 'NS' bits are critical)

For your own custom transformers (say you have a class called 'PermittedTypes' you should have that as an encoding/decoding class and a linked swift file called something like PermittedTypesTransformer.swift In BOTH classes add the line: @objc('the class name) to the line BEFORE the class declaration. Now in xcdatamodel your custom Transformable should be converted from something like [PermittedTypes] to NSArray<PermittedTypes>

These technique allows you to keep your strong typing on any transformable, unlike the answers above which suggested [String] or [Int] or anything should become NSArray, rather than NSArray<NS{type}> or NSArray<CustomType name> Same works if you are converting arrays, like [String: Any] becoming NSDictionary or [[String:Any]] becoming NSArray<NSDictionary>

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.

Core Data transformable attribute problem in Xcode16
 
 
Q