How to add a Package in SwiftUI project – Xcode
In this tutorial, I will show you how to add a Package dependency in SwiftUI project in Xcode. This will work on any Xcode project. (Not only SwiftUI)
Steps involved:
- Open your Project in Xcode.
- Right-click on the left sidebar of your Xcode window.
- Click on “Add package dependencies…”
- Now you will get the option to search for available packages. (Or you can also paste the direct package link)
After clicking on that you will get something like this:
From the top right search box, you can search for packages or you can paste the package URL directly.
The package should must have a file named Package.swift
Add package from Github in Xcode
Just open the Github repo page of your desired package that you want to add in Xcode.
You will get an option to copy the HTTPS url.
Just copy it and paste it in the search box.
For example if you want to add Kingfisher package then just go to google search for Kingfisher github.
The exact URL is https://github.com/onevcat/Kingfisher
Now simply paste that copied URL in your Xcode package adding search or URL box.
Note: If you wish to use the package in your project, make sure you have imported that package in your Swift file.
For example if I want to add the Kingfisher package in my file, I will be adding this line in my Swift file:
import Kingfisher
Add a local package in Xcode project
On the package adding window in Xcode, at the bottom left cornet there is a button “Local…”
Click on that button and then upload the directory of the package.
In that directory there must be a file named Package.swift
There is an alternative way to go to the package adding window.
Check how I do this in the below image:
Click on File => Add package dependencies
That’s all.
Leave a Reply