How to Add External Libraries to a SwiftUI Project Using Swift Package Manager
Tags: swift, ios, swiftui
Published: 2021-03-24 21:23:07

---
title: How to Add External Libraries to a SwiftUI Project Using Swift Package Manager
published: true
description: 
tags: #swift #ios #swiftui
//cover_image: https://direct_url_to_image.jpg
---
<!-- wp:paragraph -->
<p>In this post we are going to look at how we can add a Swift package to our SwiftUI Project. Let's start by going to the <meta charset="utf-8"><a href="http://swiftpackageindex.com">Swift Package Index</a> website and searching through the libraries. For this post we are going to use the <meta charset="utf-8"><a href="https://swiftpackageindex.com/AppPear/ChartView">SwiftUICharts</a> package to add to our project.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":1645,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="https://swifttom.com/wp-content/uploads/2021/03/Screen-Shot-2021-03-19-at-6.42.32-PM.png" alt="" class="wp-image-1645"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>SwiftUICharts</strong> is an amazing library that makes it super easy to get beautifully animated charts into your SwiftUI project. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now that we have picked the library we want to add to our project, we now need to click on the copy button under the <meta charset="utf-8"><strong>SwiftUICharts</strong> title. This copies the link to <meta charset="utf-8"><strong>SwiftUICharts</strong> <strong>GitHub</strong> so that we can download the package to our project. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now that we have our link to <meta charset="utf-8"><strong>SwiftUICharts</strong> repo, we will need to go to our Xcode project and click on <strong>File</strong> <strong>&gt;</strong> <strong>Swift</strong> <strong>Packages</strong> <strong>&gt; Add Package Dependency</strong> and then paste in the repo's url:&nbsp;<code><strong>https://github.com/AppPear/ChartView</strong></code></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1648,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://swifttom.com/wp-content/uploads/2021/03/Screen-Shot-2021-03-22-at-2.15.39-PM-1024x622.png" alt="" class="wp-image-1648"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Once you click on the next button, you will then have to choose what version, branch or commit from the package you would like to use.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1649,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://swifttom.com/wp-content/uploads/2021/03/Screen-Shot-2021-03-22-at-2.17.25-PM-1024x612.png" alt="" class="wp-image-1649"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here we will not mess with any of the options and just click on the next button. This will now download the package into your Xcode project. Once downloaded, we will make sure our package is selected and click on the finish button. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now we should see that our package has been successfully added to our project.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1651,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://swifttom.com/wp-content/uploads/2021/03/Screen-Shot-2021-03-22-at-2.21.29-PM-1024x327.png" alt="" class="wp-image-1651"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Thats all there is too it! </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>From here we can import the <meta charset="utf-8"><strong>SwiftUICharts</strong> library into a file and start using all the amazing charts and animations <meta charset="utf-8"><strong>SwiftUICharts</strong> has to offer. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you would like a deeper dive into <strong>Swift Package Manager</strong> I would recommend checking out this <a href="https://medium.com/xcblog/apple-swift-package-manager-a-deep-dive-ebe6909a5284">great article</a> by @Shashikant86 </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Thanks for reading and happy coding!</p>
<!-- /wp:paragraph -->