iOS networking 2023 module 3 lesson 5 canvas crash

In Chris’ video at 8:56 the canvas crashes when he tries to run his app, the very same happens in my computer too. Yet, the simulator works fine. Is there any reason, and any fix to this?

@Stephane

Hi Stephane,

Welcome to the community.

At this point?

Essentially what you have to do with any View is provide a means of getting data to the View. That also is true for any Preview to work. That could be a simple as adding an .enviroment(ViewModel()) to the View in the Preview code. ie, in this instance all you need to do is this:

#Preview {
    ContentView()
        .environment(ViewModel())
}

That fixes it, thank you!

1 Like