The Bundle
class in Swift provides access to resources stored within a directory structure. When an app is built, various assets and files are packaged into its main bundle, which is essentially a container directory for all the resources needed by the app. You can access this main bundle using Bundle.main
.
The Bundle
class includes methods that help locate and load resources, making it an essential tool when working with mock data in development environments.
Creating a Mock Data File
We can use this to load mock data, let's make an example to load an array of users from a JSON file. Start creating a JSON file named user_mock_data.json
with sample user data:
[
{
"id": 1,
"name": "Alice",
"email": "alice@example.com"
},
{
"id": 2,
"name": "Bob",
"email": "bob@example.com"
}
]
Continue reading
Access to all the content with our plans.
- Junior level content
- Senior level content
- Expert level content
- Extra content
- Question submissions
Be the first to comment