Create a Swift Package and use it in a Local Xcode Project

Create and Import a Swift Package locally

Johann Fong
Feb 26 · 3 min read

At some point in time during your swift journey you might you would want to create your own Swift Package. If you are like me and prefer to have things working on a local repo before pushing it to a remote repository this is a guide for you.

I’m using Xcode 12.4 but the concept should work for you if you are using 11 and later.

The Recipe

  1. Create a Swift Package
  2. ‘Git’ up the package
  3. Import your package and build!

1. Create a Swift Package

To create a swift package, launch Xcode. Go to File > New > Swift Package… Alternatively, you can use the keyboard shortcut ⌘⌃⇧N.

Navigate it to your ‘Desktop’, name your package and click ‘Create’. In this case, I have named my package as the default name ‘MyLibrary’.

2. ‘Git’ up the package

Swift Package Manager requires Git at runtime as well as build-time.

So what we have to do now is to Git initialize our package and tag it with a version so we can import it into our project.

Remember to change ‘MyLibrary’ to what you have named your package to be.

We have now ‘Git’ up the package!

3. Import the package and build!

We have come to the final step! we can now import and use the Package.

To do so open the desired Xcode project you want to use the package in.

In the Project Navigator select the blue icon with your project name.

In the main view select the white icon with your project name under ‘TARGETS’ and scroll down until you see ‘Frameworks, Libraries, and Embedded Content’.

Click on the ‘+’.

Next Click ‘Add Other…’> Select ‘Add Package Dependency…’.

In the search bar enter the location of your package. In my case, ‘MyLibrary’ is still on my desktop so I’ll use the following.

Click ‘Next’ > Click ‘Next’ Again> Click ‘Finish’

Press ⌘+B to build your project. After which you can import your package

That’s It!

In the next article, I’ll share how to create a Swift Package with a Demo Project in a single workspace! Look out for it!

Meanwhile, please feel free to comment below, if you have any questions.

Thanks for reading!

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To stay up to date on other topics, follow us on LinkedIn. https://www.linkedin.com/company/nerdfortech

Johann Fong

Written by

Documenting my Development in Software Development

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To stay up to date on other topics, follow us on LinkedIn. https://www.linkedin.com/company/nerdfortech

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store