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.

Rollbacks

Rollbacks

- [Instructor] Once you use programmatic saving, you can use rollbacks as an alternative to undo. To understand this, let's look at three properties of model context. These are raised which indicate pending changes to the persistent model. I'm going to stop the app here and I'm going to go up into my code just above the body here, and I'm going to put a function in here. You can go ahead and type that out. I just saved myself some time, it didn't end, pasted it in. But essentially what you have is you have three arrays, the inserted models array, the changed models array, and the deleted models array. Every time you do an insert change or delete, it puts stuff into the model context array to tell you it's in that kind of state. So let's go down to the add button that we have before. And just after save ticket, I'll add that function and I'll do the same thing for the delete a little further up here, and I'll comment out that save and replace it with model arrays. All right, and then…

Contents