Using mock data for previews
So far, we've built apps using our own data. However, when dealing with large projects, data is usually obtained by making API calls. However, that can be time-consuming and quickly become a bottleneck for our previews. The better option is to make some mock data available for previews only. We can tell Xcode not to bundle the data and resources used for previews with our app when we submit the app to the App Store.In this recipe, we will store some mock JavaScript Object Notation (JSON) data on insects in our Preview Content folder and fetch our data from the file, instead of making API calls. JSON is a lightweight format used to store and transfer data.
Getting ready
Create a new SwiftUI project called UsingMockDataForPreviews.To get access to the files used here, clone/download this project from GitHub: https://github.com/PacktPublishing/SwiftUI-Cookbook-3rd-Edition.
How to do it…
We will add a JSON file with sample data to our Xcode project...