Creating the first SwiftUI package.
An Tran • June 12, 2019ios swiftui swift-package-manager
Swift Package Manager has been first introduced since last WWDC. Unfortunately iOS hasn't been supported, the tooling is not well integrated into Xcode.
Everything has changed now after WWDC 2019. Xcode 11 integrates SPM directly. iOS Platform is also supported by SPM.
Xcode integration of SPM fantastic. You can not only import packages, but also create packges easily.
I have followed the session Creating Swift Packages to extract part of my code that showing a loading indicator into a separated Swift Package. Code is here: https://github.com/peacemoon/SwiftyUIView. The steps are easy to follow and very straightforward.
There are only some canveats that I want to share with you:
If you create the packages by copying codes from your project, you will probably see some error like this.
The reason is that Swift Packages are platform independent. It will be compiled to specific platforms when your app projects are compiled.
You can solve that easy by adding
@availableanotation to specify which platforms your packages support.
You need to add
publicto all public classes/structs since they are not in your project anymore.