Post

Replies

Boosts

Views

Activity

Reply to Error generating files in compilation cause AppEntity and Widget Extension on iOS17
Creating a "wrapper" AppEntity worked for me. In OP's example, this would be something like: struct HabitatAppEntity: AppEntity, Identifiable { let id = UUID() let habitat: Habit static var defaultQuery = HabitEntityQuery() static var typeDisplayRepresentation: TypeDisplayRepresentation = "Hábito" var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(habitat.nombre)") } } Xcode 16 Beta 3 seems to work as intended, so hopefully this workaround isn't required for too long :)
Jul ’24
Reply to Thread 1: "Model already contains an entity named <member>."
A workaround for this is to specify a ModelConfiguration that uses a different database file for each type. My solution is based off the example code shown in wwdc2023-10196. It should be noted that the example code fails with the error "Cannot use instance member '' within property initializer; property initializers run before 'self' is available", so I had to move the ModelContainer initialisation into .modelContainer. import SwiftUI import SwiftData @main struct TestApp: App { let fullSchema = Schema([ Item.self, DuplicateItem.self ]) let itemModelConfiguration = ModelConfiguration( schema: Schema([ Item.self ]), url: URL.applicationSupportDirectory.appendingPathComponent("item.store") ) let duplicateItemModelConfiguration = ModelConfiguration( schema: Schema([ DuplicateItem.self ]), url: URL.applicationSupportDirectory.appendingPathComponent("duplicateItem.store") ) var body: some Scene { WindowGroup { ContentView() } .modelContainer(try! ModelContainer(for: fullSchema, itemModelConfiguration, duplicateItemModelConfiguration) ) } }
Jul ’23