How to delete all objects from SwiftData in Swift
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![Three flowers that represent Swift, Swift Data and Xcode. The text "Delete all Objects from a SwiftData Persistent Container" sits beneath them.](https://www.delasign.com/CDN/images/How-to-delete-all-objects-from-SwiftData-in-Swift.webp)
A step by step guide on deleting all objects in a SwiftData persistent storage container using SwiftUI, UIKit or AppKit.
![A screenshot of an iPhone showing the result of the sample app available on our open source swift GitHub repository.](https://www.delasign.com/CDN/images/Result_1920x1280.webp)
The following tutorial has been made available, along with a simple app for demonstrating SwiftData, through the tutorial/swift-data-basics branch on our Open Source Swift Starter Project.
git clone git@github.com:delasign/swift-starter-project.git
Step One: Setup the Project
![A screenshot of Xcode showing the sample functionality that adds a new SwiftData object to a persistent container. The code snippet is available below.](https://www.delasign.com/CDN/images/Add-Create-Functionality.webp)
Follow the tutorial linked below to add SwiftData to your project, along with the ability to add objects.
Step Two: Add the Delete All Functionality
![A screenshot of XCode that highlights the sample functionality that can be used to delete all objects from a SwiftData persistent container. The code snippet is available below.](https://www.delasign.com/CDN/images/Delete-All-Functionality.webp)
Add functionality similar that below to the project to delete all objects from a SwiftData persistent storage container.
We recommend adding this to a file called DataCoordinator+SwiftData.swift, where DataCoordinator is the name of the MainActor singleton that manages the SwiftData.
Step Three: Test
![A screenshot of an iPhone showing the result of the sample app available on our open source swift GitHub repository.](https://www.delasign.com/CDN/images/Result_1920x1280.webp)
Add functionality to delete all SwiftData objects by calling the function created in Step Two.
Then, run the app and test that it works.
Looking to learn more about things you can do with SwiftData, Swift or XCode ?
Consult our quick start guide or search our blog to find educational content on learning how to use SwiftData, Swift or XCode.