How to Build Swift PackageSeptember 29, 2021 Publish By : EXPERT APP DEVS 2 min read Viewed By : 826
What is a Swift Package Manager?
- This is a tool for managing and distributing swift code.
- It can integrate with swift build system of the auto process like downloading, compiling, and linking dependency
- SPM is used easily to manage your project dependency.
Why use SPM?
- SPM setup is very simple and easy.
- This can also work on Linux.
- SPM provides native solutions by apple.
Create iOS app
- First, create an iOS app then you can see something like this:-
- If you try to run this app it gives an error like no calculator.framework module.
- Now we will create a swift package and link in our iOS app.
Swift Package in a Git repository
- Create a new repository by following steps:- Open Xcode - Click on file - new - Swift package.
- Give the name of your swift package and click on create.
- Now open a terminal and run this command:- git init
- Now you will see this:-
- Now add code already we had in calculator.framework
- So we will show something like this:-
- Add new file XCTestManifests.swift and write the below code in this file
- Now create a new file as LinuxMain.swift and write the below code in this file
- Now navigate to our CalculaterTest and add to the test it.
- Now our swift Package building is finished.
- Let’s use it in our project.
- Go to your iOS app Click on file - swift packages - Add package dependency and type git repository URL.
- Now click on next and choose anyone from three options ( Version, Branch or commit)
- You will see below screen:-
- Now click on finish then Xcode will finish resolving and fetching the package dependency.
- Once you click on the finish you will see dependency on the left side of your project.
- If you want to change the package requirement you need to select a project and click on the swift package, then double click on the package you want to change.
Need a consultation?
Drop us a line! We are here to answer your questions 24/7.