Post

Replies

Boosts

Views

Activity

Issue with SwiftData inheritance
Every time I insert a subclass (MYShapeLayer) into the model context, the app crashes with an error: DesignerPlayground crashed due to fatalError in BackingData.swift at line 908. Never access a full future backing data - PersistentIdentifier(id: SwiftData.PersistentIdentifier.ID(backing: SwiftData.PersistentIdentifier.PersistentIdentifierBacking.managedObjectID(0xb2dbc55f3f4c57f2 <x-coredata://B1E3206B-40DE-4185-BC65-4540B4705B40/MYShapeLayer/p1>))) with Optional(A6CA4F89-107F-4A66-BC49-DD7DAC689F77) struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query private var designs: [MYDesign] var layers: [MYLayer] { designs.first?.layers ?? [] } var body: some View { NavigationStack { List { ForEach(layers) { layer in Text(layer.description) } } .onAppear { let design = MYDesign(title: "My Design") modelContext.insert(design) try? modelContext.save() } .toolbar { Menu("Add", systemImage: "plus") { Button(action: addTextLayer) { Text("Add Text Layer") } Button(action: addShapeLayer) { Text("Add Shape Layer") } } } } } private func addTextLayer() { if let design = designs.first { let newLayer = MYLayer(order: layers.count, kind: .text) newLayer.design = design modelContext.insert(newLayer) try? modelContext.save() } } private func addShapeLayer() { if let design = designs.first { let newLayer = MYShapeLayer(shapeName: "Ellipse", order: layers.count) newLayer.design = design modelContext.insert(newLayer) try? modelContext.save() } } } #Preview { ContentView() .modelContainer(for: [MYDesign.self, MYLayer.self, MYShapeLayer.self], inMemory: true) } @Model final class MYDesign { var title: String = "" @Relationship(deleteRule: .cascade, inverse: \MYLayer.design) var layers: [MYLayer] = [] init(title: String = "") { self.title = title } } @available(iOS 26.0, macOS 26.0, *) @Model class MYLayer { var design: MYDesign! var order: Int = 0 var title: String = "" init(order: Int = 0, title: String = "New Layer") { self.order = order self.title = title } } @available(iOS 26.0, macOS 26.0, *) @Model class MYShapeLayer: MYLayer { var shapeName: String = "" init(shapeName: String, order: Int = 0) { self.shapeName = shapeName super.init(order: order) } }
1
0
144
Sep ’25
Dynamic Presentation Sheet Heights
In my application, I have NavigationStack presented as a sheet, and I intend to dynamically adjust its height while pushing views within it. I'm utilizing a global observable variable to manage the height and everything works fine except that the height changes abruptly without any animation. It abruptly transitions from one height to another. The issue can be reproduced using the following code: #Preview { @Previewable @State var height: CGFloat = 200 Text("Parent View") .sheet(isPresented: .constant(true)) { NavigationStack { Form { NavigationLink("Button") { RoundedRectangle(cornerRadius: 20) .fill(Color.blue) .frame(height: 200) .navigationTitle("Child") .onAppear { withAnimation { height = 300 } } } } .navigationTitle("Parent") .navigationBarTitleDisplayMode(.inline) .presentationDetents([.height(height)]) .onAppear { withAnimation { height = 150 } } } } }
3
0
115
Jul ’25