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 :)
Topic: Machine Learning & AI SubTopic: General Tags:
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
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 :)
Topic: Machine Learning & AI SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’24
Reply to FileDocument - open another file in the same directory as selected file
I decided to disable the App Sandbox here - my app was built off a legacy system that depends on being able to access relative paths.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’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) ) } }
Replies
Boosts
Views
Activity
Jul ’23
Reply to Thread 1: "Model already contains an entity named <member>."
I've got a minimal reproduction working. @Model class Item { var test: [Int] init(test: [Int]) { self.test = test } } @Model class DuplicateItem { var test: [Int] init(test: [Int]) { self.test = test } } Internally, SwiftData makes an SQL database and adds a table called Z<MEMBER>. It tries to make this twice, and fails.
Replies
Boosts
Views
Activity
Jul ’23
Reply to SwiftData - Thread 1: Fatal error: Illegal attempt to use a nil as an Attribute
SwiftData doesn't like enums at the moment, this video shows a workaround: https://www.youtube.com/watch?v=yOqGva62nzg Basically, store the enum as a string, and compute the enum at runtime. Is this bug reported? I'd consider it a showstopper.
Replies
Boosts
Views
Activity
Jul ’23