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.
Delete data - Swift Tutorial
From the course: SwiftData Essential Training
Delete data
- [Instructor] Now, you or your users are not going to delete the app every time you want to delete a single record. That's an impractical all or nothing solution. Swift data through the model context allows you to delete individual records. So let's stop the app and scroll down to where it says deletion goes here, which should be down here somewhere. Okay, all right, and where we're there I'm going to activate this by using the on delete modifier of list on the for each as though it were an array. So just same way we do it any other time on delete. And then we'll put index set in like that. What I'm going to do is I'm going to take an index and delete the object at the index of the model using delete method of model context. Again, this works the same way as an array, but we're going to use a model context instead. So we're going to do four index in index set, and then inside of that we're going to do a model context, delete, and we're going to do the ratings at that index. And that…