I have a question about SwiftData and mapping two data models. I have an app structure in mind that is very similar to the Moonshot app example, Day 39. I've translated this project to SwiftData as a trial project.
The only error that I receive has to do with not conforming to the protocol 'PersistentModel' when loading one of the json files:
Type 'Dictionary<String, Activity>.Element' (aka '(key: String, value: Activity)') does not conform to protocol 'PersistentModel'
I have two json files: recommendations (similar to mission.json) and activities (similar to astronauts.json) with the corresponding SwiftData classes Recommendation and Activity.
The problem might have to do with the structure of the activities dictionary: a dictionary of dictionaries.
The error occurs when retrieving the data:
@Query var activities: [String: Activity]
Which does the following in the background:
private (set) var _activities: SwiftData.Query<[String: Activity].Element, [String: Activity]> = .init()
Where [String: Activity] seems to cause the problem.
Does anyone have encountered this same problem? Or knows how to solve it?