Post

Replies

Boosts

Views

Activity

Reply to Trace/BPT trap: 5
I had the exact same issue with a SwiftUI application I am working on, and I found what was causing it for me (it may be different for you, but it's worth a check). By default, a fresh SwiftUI file will contain the actual view code and a preview block to generate that view code in the canvas. On some of my view files, I just deleted the preview block (since it isn't strictly needed, as you can still run your app in the simulator). On one of my views (called "TestView.swift"), I had not deleted the preview block, nor had I modified it so it would work properly. The problem was that the EnvironmentObject I instantiated in the base parent view (the app entry point) was being passed to each individual view file that required it (which was most of them since this EnvironmentObject happens to be the ViewModel that powers the logic of my app), including TestView, but it wasn't being referenced at all in TestView's preview block. Without any reference to that parent environment object, the app sort of freaks out and throws this error. To fix it, I could have just deleted the preview block here as well, but instead I created a dummy instance of my ViewModel (that base environment object-- called ContentModel in my app) and passed it into the .environmentObject modifier for the view in the preview block. To illustrate, here is the code with that modifier added: struct TestView_Previews: PreviewProvider {   static var previews: some View {     TestView()       .environmentObject(ContentModel())   } } Adding this just shows a sort of dummy preview in the canvas, but at least it doesn't crash anymore. I hope this made sense and it helps you solve your own issue. Maybe you have one of these default preview blocks somewhere that you need to either modify or delete. Good luck! -Kaleb W. -AppKid LLC
May ’22