From the course: SwiftData Essential Training
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Custom model containers - Swift Tutorial
From the course: SwiftData Essential Training
Custom model containers
- [Instructor] With some basic knowledge of model containers, we can explore more features that give you control over the models. Instead of the direct assignment we did in previews, you'll find setting up a functional computed property for a model container will keep your code more organized. So I'm going to add a computed property in a separate file. So let's just go over here and I'll just hit HuliPizzaPersistent and do a Command + N and we're just going to make a Swift file. And we'll call this ModelContainer. And we want it in the Huli Pizza Persistent group and we're all set to go, good. All right, and it's all the way here on the bottom. I'm going to scoot it all the way up to here where my app is so I can keep, 'cause these two are really related. And it doesn't have much in here. I'll import SwiftData into here. Let's stick a computed property called modelContainer, and it's going to be a model container. Inside this, I'm going to add a schema. As we discussed before, a…