Modularizing SwiftUI Projects

Get separate!

Steven Curtis

--

Photo by Volodymyr Hryshchenko on Unsplash

In this particular tutorial I want to cover modularization. Specifically I want to cover having a UIComponent library and how this might actually be used in practice to sample what your components might be and integrate them into your project.

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.4, and Swift 5.7.2

Prerequisites:

You need to be able to code in Swift, perhaps using Playgrounds

Don’t bore us, get to it!

Create a new project

Name the main module

This is the entry point to the App and will contain the other modules. Typically this would contain things like modules responsible for networking and shared components (etc.).

Create A Shared Components Framework

I’m going to create a new project for my components. The idea here is that I can create some buttons and views that can be used anywhere within my fun App!

This time rather than creating a new project I’ll create a new framework.

I then call fill out the following fields for the component library:

I don’t need tests for this one as it’s goig to be UI only (discuss this choice in the comments).

I’m going to setup a simple button in the framework. Here is the code for my button. Note that the initializer needs to be public so it is accessible from outside it’s…

--

--