
SwiftUI Cookbook
By :

So far, we've built apps using our own data. However, when building an app for a client, you may want to use mock data that closely resembles client data. Using API calls early on in development may be a bottleneck. In this recipe, we will introduce a faster option, using JSON data stored in a file.
In this recipe, we will read Insect
data from a JSON file and display the content in a SwiftUI view.
Let's create a new project called UsingMockDataForPreviews
.
If not yet done, clone this book's GitHub repository from https://github.com/PacktPublishing/SwiftUI-Cookbook.
We will add our mock data to the Xcode project, then proceed to design a SwiftUI view that elegantly displays the data. The steps are as follows:
Resources
file, then drag and drop the insectData.json
file into the Preview Content
folder of the Xcode project:Figure 3.16 –...