How to create an Example App for your Swift Package Manager package module.
The following article is part 4 of a 4-part series on modularisation in iOS with Swift Package Manager and some approaches we may take. If you missed out on part 1, part 2 or part 3, feel free to check it out. As a reference for examples, we will be using this GitHub Repository
Creating an Example App for our module
Once we have a package module setup using Swift Package Manager as we did in part 2 We may want to consider adding an Example App.
The purpose of this app would be to be able to run UI for our module in isolation without running our main app. The app will build and compile a lot faster and we are free to configure the app we want to show our UI, leading to speed up in development. To create an Example App select the plus button in your project to add a new target.
In our example, we will be creating an iOS application
Name your Example App accordingly
You should now see your newly created example app.
Linking our package to the Example App build phases
To use our package in our example app we would need to link the binary to our build phases as we did in part 3. To do this head over to the build phases of the new example app and add your package.
Using our module in the Example App
Once this is done, we can use the package in the example app. For this example head over to the SceneDelegate and add the following code to create our UI used in the Feature1Module.
When we run the app we can then see just the UI of our Feature1Module and we can begin to work on this module in isolation
This concludes our series Modularisation in iOS using Swift Package Manager and some approaches we may take. Thank you for taking the time to give it a read. Feel free to follow me on Twitter.