SwiftData iOS18: "Could not materialize Objective-C class named "Set" from declared attribute value type "Set<String>" of attribute named..."

Posting here to see if folks have workarounds or if I have a misunderstanding of SwiftData supported types.

In adopting SwiftData, I have swiftData properties of collection type (Array or Set - both have this issue). E.g:

@Model
final class Item {
    var timestamp: Date
    var strings = ["aa", "bb"]
    
    var display: String {
        strings.joined(separator: " ")
    }
    
    init(timestamp: Date) {
        self.timestamp = timestamp
    }
}

So far in development I haven't had issues on iOS 17, but on the iOS 18 betas 4-5 the app logs show the following error:

"fault: Could not materialize Objective-C class named "Array" from declared attribute value type "Array<String>" of attribute named strings"

It happens immediately in my app when creating an object with a collection attribute. In a minimal test example, the error log appears only after a few minutes and doesn't seem to affect the template app's basic functionality.

Anyone else running into this?

Was filed as FB14397250

Swapping out the Item.swift file in Xcode's default project with Swift Data seems to work fine. Could you provide more steps to reproduce?

With that minimal example, (now testing on beta 6), if you add some items, after ~45 seconds those faults appear in the logs. This happens consistently, though doesn't seem to affect functionality.

In beta 6, my larger app seems to be able to function fine while still emitting these log lines (previously it would fail to save new models in the context)

I'm getting similar logs in my production app on iOS 18. CoreData: Could not materialize Objective-C class named "Array" from declared attribute value type "Array<String>" of attribute named ***

Have a similar issue (same error) just using CoreData with a transformable attribute with a NSSecureUnarchiveFromDataTransformer transformer and a Custom Class of Set<String>.

Frustratingly this error happens in some unit tests, but not consistently. Using NSSet appears to be working for the moment, but I'm not confident that it's gone unless I can reproduce the issue consistently.

@mark-ger

Was filed as FB14397250

Shows "Feedback not found"

SwiftData iOS18: "Could not materialize Objective-C class named "Set" from declared attribute value type "Set&lt;String&gt;" of attribute named..."
 
 
Q