How to add a swift package to iOS App using the Swift Package Manager
I’m going to show you how to add a swift package to your iOS app using the Swift Package Manager.
First how to add a package to your app
To add a package you will need a repository’s URL or if the package is hosted on GitHub or GitHub enterprise and you’re logged in you can just search for the package.
There’s actually two ways.
Here is way number 1:
- Navigate to the target’s general pane
- Click the
+button in the
Frameworks, Libraries, and Embedded Content
- Click on
Add Package Dependecy
Here is way number 2:
- Open the project
- Go to the File Menu
- Choose Swift Packages and enter the repo URL
How to use the dependency?
To actually use the dependency, you will need to first import the package and then call the property you want.
How to delete a package from your app
- Navigate to the swift packages pane in the Project settings
- Select the package to delete
- Hit the
When should you reach for an external dependency?
An external dependency aka package can make your life easier as a developer. Sometimes they can save you hours of coding and figuring out how something works.
I use one in iHog for OSC a network protocol that I have no idea how to actually implement in Swift. OSCKit allowed me to focus on other parts of the app and for the package to actually handle all the OSC communication between the app, the iOS device, and the Hog controller.