Provide Sample Data for SwiftUI Previews | Preview App on Xcode Canvas | SwiftUI & SwiftData - 4/9

Опубликовано: 26 Март 2026
на канале: Think Like an Engineer
551
22

Learn How to Use Sample Data for Previews in Xcode!

In this video, we’ll show you how to effortlessly preview your SwiftUI views in Xcode without manually adding sample data each time. We’ll create a SampleData class that provides sample data for your previews with just one line of code, no more losing data when the canvas refreshes!

What You’ll Learn:
✅ How to create a SampleData class for previews
✅ How to use an in-memory model container for sample data
✅ How to automatically insert sample data into previews
✅ How to simplify your preview setup in SwiftUI

Related Videos:
📌    • Insert Data with SwiftData & SwiftUI - 1/9  
📌    • Query Data with SwiftData | Get All Data, ...  
📌    • Navigate between Views using NavigationLin...  

Chapters:
00:00 Introduction
00:22 Quick Recap of the Sample Project
01:52 Create Sample Data Class
05:23 Provide Sample Data to the List View
06:06 Provide Sample Data to the Detail View
07:01 How to Update Sample Data Class if Required
07:15 Showcase


🔔 If you found this tutorial helpful, don’t forget to subscribe and leave a comment below, what you would like to learn next!

#Xcode #preview #SwiftUI #SwiftData #canvas