I'm developing an app with dynamic intents fetched from a SwiftData container with data that is configured inside the app. However, the following happens when .fetch() is run during widget configuration.
When creating a new instance of the model and inserting it into the container, it disappears when the app is relaunched.
When creating a new instance of the model and inserting it into the container, and then attempting to delete that instance, the app crashes. This error shows up Could not cast value of type 'Swift.Optional<Any>' (0x2003ddfc0) to 'Foundation.UUID' (0x200442af8).
This is a snippet of the query code.
func entities(for identifiers: [ExampleEntity.ID]) async throws -> [ExampleEntity] {
let modelContext = ModelContext(Self.container)
let examples = try? modelContext.fetch(FetchDescriptor<ExampleModel>())
return examples?.map {
ExampleEntity(example: $0)
} ?? []
}
SwiftData works as expected as long as the .fetch() is not called in the EntityQuery.