Member-only story
Moving SwiftUI Views and Models Into Separate Swift Packages
Write modular code

Swift packages are a great way to separate our code into modules that we can use across multiple projects.
This is a simple guide to using them for SwiftUI, but any Swift code can be distributed this way.
Creating The MyViews Package
Open Xcode and click File > New > Package… or alternatively press Command, Control, Shift, and N. It’s useful to create a new folder for this project, which you can do with the New folder button when you’ve decided where you want to put your files. I called my new folder PackagesExample
, but the name doesn’t matter. Call your package MyViews
and make sure it is not added to any projects or workspaces.
The Sources folder in your package will have separate folders for each target.
Create two new folders with Swift files inside like this:
MyViews/Sources/MyViews/MyViews.swift
MyViews/Sources/HelloButton/HelloButton.swift
Open up HelloButton.swift
and add this: