From the course: SwiftData Essential Training

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Add SwiftUI previews

Add SwiftUI previews

- [Instructor] Up till now, we've been avoiding previews with SwiftData because it crashes the previews. Let's take a look at that. I'm going to go shut off. Yeah, we don't need this anymore, so I'll drop that down here. I'm going to go over here to NamesListView and pull up the preview. And we'll start the preview. And as you see, the preview crashes, so I'm going to go close the preview for the moment, and so that's a command return. And it crashed the whole thing, so I'll have to reopen. The last part of this course covers why that crashed, how to fix it and fix all those deletions you've been doing to the app. So head over to HuliPizzaPersistentApp. Several times, we've added to the model container here. The model container manages the storage for SwiftData. If that's not there, the app crashes. That's what's happening in the previews. Since they don't have their own model container to store, they crash. We can add a model container to a preview directly and see that view…

Contents