<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>swift package &#8211; swiftyplace</title>
	<atom:link href="https://www.swiftyplace.com/blog/tag/swift-package/feed" rel="self" type="application/rss+xml" />
	<link>https://www.swiftyplace.com</link>
	<description>Learn how to build amazing apps with SwiftUI and Combine</description>
	<lastBuildDate>Tue, 09 Jan 2024 16:36:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.swiftyplace.com/wp-content/uploads/2023/08/cropped-logo-1-32x32.png</url>
	<title>swift package &#8211; swiftyplace</title>
	<link>https://www.swiftyplace.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to add third-party libraries in Xcode using Swift Package Manager</title>
		<link>https://www.swiftyplace.com/blog/swift-package-manager-xcode?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=swift-package-manager-xcode</link>
					<comments>https://www.swiftyplace.com/blog/swift-package-manager-xcode#respond</comments>
		
		<dc:creator><![CDATA[Karin Prater]]></dc:creator>
		<pubDate>Wed, 27 Sep 2023 08:01:22 +0000</pubDate>
				<category><![CDATA[Xcode]]></category>
		<category><![CDATA[cocoapods vs swift package manager]]></category>
		<category><![CDATA[package dependency]]></category>
		<category><![CDATA[swift framework]]></category>
		<category><![CDATA[swift package]]></category>
		<category><![CDATA[swift package dependency]]></category>
		<category><![CDATA[swift package manager]]></category>
		<category><![CDATA[swift package manager vs cocoapods]]></category>
		<guid isPermaLink="false">https://www.swiftyplace.com/?p=2973</guid>

					<description><![CDATA[<p>Learn how to easily add third-party libraries and frameworks in Xcode using Swift Package Manager. Simplify your development process today!</p>
<p>The post <a rel="nofollow" href="https://www.swiftyplace.com/blog/swift-package-manager-xcode">How to add third-party libraries in Xcode using Swift Package Manager</a> appeared first on <a rel="nofollow" href="https://www.swiftyplace.com">swiftyplace</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this tutorial, I will guide you through the process of adding third-party libraries and frameworks to your Xcode projects using Swift Package Manager. By leveraging the power of this tool, you can streamline your development workflow and enhance the functionality of your iOS apps.</p>



<p>But that’s not all! If you’re new to Swift Package Manager or want to learn more about its capabilities, make sure to check out my previous blog post on&nbsp;<a href="https://www.swiftyplace.com/blog/modular-code-with-swift-package-manager">How to Create Your First Package with Swift Package Manager</a>. This tutorial will introduce you to the fundamentals of creating and integrating Swift packages locally in Xcode, empowering you to share your code efficiently on GitHub.</p>



<p>Additionally, if you’re interested in authenticating GitHub directly from Xcode to save time and improve collaboration, take a look at my upcoming blog post on&nbsp;<a href="https://www.swiftyplace.com/blog/xcode-github-access-token">How to Integrate Xcode with GitHub Access Token</a>. This post will demonstrate how to seamlessly integrate GitHub using access tokens, allowing for a smoother and more secure development experience.</p>



<p>I’m excited to share these valuable insights with you, so let’s dive right in and discover how Swift Package Manager can signifacantly improve your iOS development process!</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">What is the Swift Package Manager in Swift?</h2>



<p>Swift Packages is a dependency management solution introduced by Apple to streamline the inclusion of external libraries and frameworks into your Xcode projects. They offer a standardized way of distributing Swift code and its dependencies, making it easier to manage third-party code and share your own code across different projects.</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Swift Package Manager (SPM) vs CocoaPods vs Carthage</h3>



<p>Swift Package Manager (SPM) is the official and most commonly used package manager for managing dependencies in Swift projects. However, there are a few alternative package managers and dependency management approaches you can consider:</p>



<ul class="wp-block-list">
<li><p><strong>CocoaPods</strong> is a popular dependency manager for iOS and macOS projects. It uses Ruby as its primary programming language and provides a centralized repository for Swift and Objective-C libraries. While it&#8217;s more commonly associated with Objective-C projects, CocoaPods has support for Swift as well.</p></li>



<li><strong>Carthage</strong>&nbsp;is another dependency manager for Swift and Objective-C. Unlike CocoaPods, Carthage focuses on decentralized dependency management. It doesn&#8217;t modify your Xcode project file but instead builds each dependency into a framework that you link to your project.</li>
</ul>



<div style="height:22px" aria-hidden="true" class="wp-block-spacer"></div>



<ol class="wp-block-list">
<li></li>
</ol>



<p>When choosing a package manager or dependency management approach for your Swift project, consider factors such as project size, community support, ease of use, and integration with your development workflow.</p>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>Before we begin, make sure you have the following prerequisites in place:</p>



<ul class="wp-block-list">
<li> <strong style="font-size: revert;">Xcode Installed</strong><span style="font-size: revert;">: Ensure you have Xcode, Apple&#8217;s integrated development environment, installed on your Mac.</span> </li>



<li> <strong style="font-size: revert;">Swift Package Manager</strong><span style="font-size: revert;">: Swift Package Manager (SPM) comes bundled with Xcode. You don&#8217;t need to install it separately.</span> </li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Adding a Swift Package to Your Xcode Project</h2>



<p>You can add a package in Xcode by opening the File tab and selecting &#8220;Add Package Dependencies&#8221;:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" src="https://www.swiftyplace.com/wp-content/uploads/2023/09/xcode_add_package_dependency-1024x689.webp" alt="add a package dependency in your Xcode project"/></figure>
</div>


<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Next you will be presented by the package manager dialog where you have to specify what package to add.&nbsp;</p>



<ol class="wp-block-list">
<li>In the top right corner enter the url where the package can be accessed</li>



<li>Select the version you want to use. You should only allow automatic updates up to the next major version (which will include major changes and probably break your project.)</li>



<li>Press &#8220;Add Package&#8221;&nbsp;</li>
</ol>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image"><img decoding="async" src="https://www.swiftyplace.com/wp-content/uploads/2023/09/xcode_select_package-1024x631.webp" alt=""/></figure>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<p>For this example, I am going to add 2 very popular packages which are:</p>



<ul class="wp-block-list">
<li>Firebase https://github.com/firebase/firebase-ios-sdk</li>



<li>SwiftyJSON: https://github.com/SwiftyJSON/SwiftyJSON</li>
</ul>



<p>Since I am using the Firebase SDK, this offers a lot of individual package products. Xcode will present another dialog where I can choose the packages. In the below example, I am adding Analytics features.</p>



<p>For SwiftJSON this is only one dependency, so you will not see this dialog.</p>


<div class="gb-container gb-container-88ba3654">
<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" src="https://www.swiftyplace.com/wp-content/uploads/2023/09/xcode_add_package_dependency_firebase.webp" alt=""/></figure>
</div>
</div>


<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Xcode will need some time to download all the resources for you. You might see some loading indicators next to your package list in the project navigator. Once Xcode finished, you should see something similar to this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" src="https://www.swiftyplace.com/wp-content/uploads/2023/09/xcode_package_list-1024x654.webp" alt="Xcode with package dependencies added"/></figure>
</div>


<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">How to Delete a Package</h2>



<p>You can delete a package in Xcode. You can find this option by:</p>



<ul class="wp-block-list">
<li>Click on your project&#8217;s name in the Project Navigator (usually on the left side of your Xcode window).</li>



<li>Select the target for which you want to add the Swift Package.</li>



<li>Navigate to the &#8220;General&#8221; tab.</li>



<li>Scroll down to the &#8220;Frameworks, Libraries and Embedded Content&#8221; section</li>
</ul>



<p>Select the package. In the above example image, I selected SwiftyJSON. You can then click on the minus button below, which will present a delete package dialog window.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>


<div class="gb-container gb-container-c5dedc2e">
<div class="gb-container gb-container-f7a433c7">
<div class="gb-container gb-container-7a8dc7a3">

<figure class="gb-block-image gb-block-image-f04fbbad"><a href="https://www.swiftyplace.com/free-swiftui-layout-cookbook" target="_blank" rel="noopener noreferrer"><img fetchpriority="high" decoding="async" width="640" height="500" class="gb-image gb-image-f04fbbad" src="http://www.swiftyplace.com/wp-content/uploads/2024/01/swiftui_roadmap_preview.webp" alt="swiftui roadmap " title="swiftui_roadmap_preview" srcset="https://www.swiftyplace.com/wp-content/uploads/2024/01/swiftui_roadmap_preview.webp 640w, https://www.swiftyplace.com/wp-content/uploads/2024/01/swiftui_roadmap_preview-300x234.webp 300w" sizes="(max-width: 640px) 100vw, 640px" /></a></figure>

</div>

<div class="gb-container gb-container-98352fe6">

<h2 class="gb-headline gb-headline-4aacd94c gb-headline-text">Feeling Lost in SwiftUI?</h2>



<p class="gb-headline gb-headline-5e6c4f85 gb-headline-text">This SwiftUI roadmap shows you what to learn next.</p>



<ul style="margin-top:0;margin-bottom:0;font-size:18px" class="wp-block-list">
<li>Key concepts at a glance</li>



<li>Spot your knowledge gaps</li>



<li>Guide your learning path</li>
</ul>


<div class="gb-container gb-container-34a8ad02">

<a class="gb-button gb-button-63e90e76 gb-button-blue" href="https://school.swiftyplace.com/f/swiftui-roadmap" target="_blank" rel="noopener noreferrer"><span class="gb-button-text">Get the FREE PDF</span><span class="gb-icon"><svg aria-hidden="true" role="img" height="1em" width="1em" viewBox="0 0 256 512" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path></svg></span></a>

</div>


<p class="gb-headline gb-headline-7ef80e86 gb-headline-text">Ideal for beginners and self-learners.</p>

</div>
</div>
</div>


<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Handling Problems with Swift Packages</h2>



<p>Xcode has options for &#8220;Reset Package Caches&#8221; &nbsp;and &#8220;Resolve Package Versions&#8221; which fixes most problems for me. This changes the &#8220;SourcePackages&#8221; to the connected folders in DerivedData. Unfortunately, Xcode will download all packages which might take some time.</p>



<p>To deal with Package issues, I simply <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f612.png" alt="😒" class="wp-smiley" style="height: 1em; max-height: 1em;" /> close/ reopen Xcode, clean the build folder, and press &nbsp;&#8220;Reset Package Caches&#8221;. What Xcode is doing internally is&nbsp;beyond me. You can read through <a href="https://www.reddit.com/r/swift/comments/yfptaf/does_anyone_find_spm_to_be_really_flaky/" target="_blank" rel="noopener">this stack overflow thread</a> for your amusement.&nbsp;</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" src="https://www.swiftyplace.com/wp-content/uploads/2023/09/xcode_packages_resolve_versions-1024x663.webp" alt="Xcode has an option to reset package caches which fixes most problems"/></figure>
</div>


<div style="height:49px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Using Features from Packages in Your Project Files</h2>



<p>After you added your dependencies to Xcode, you can start using them in code. Here is an example where I use SwiftyJSON:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono-NL.ttf" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * 1rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" data-code="import SwiftJSON

class DataFetcher: ObservableObject {
     var json: JSON = JSON.null
     ...
 }" style="color:#f6f6f4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula-soft" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F286C4">import</span><span style="color: #F6F6F4"> </span><span style="color: #97E1F1; font-style: italic">SwiftJSON</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F286C4">class</span><span style="color: #F6F6F4"> </span><span style="color: #97E1F1">DataFetcher</span><span style="color: #F6F6F4">: ObservableObject {</span></span>
<span class="line"><span style="color: #F6F6F4">     </span><span style="color: #F286C4">var</span><span style="color: #F6F6F4"> json: JSON </span><span style="color: #F286C4">=</span><span style="color: #F6F6F4"> JSON.null</span></span>
<span class="line"><span style="color: #F6F6F4">     </span><span style="color: #F286C4">...</span></span>
<span class="line"><span style="color: #F6F6F4"> }</span></span></code></pre></div>



<p>and here is how I would use Firebase Analytics to track when the user presses a button:</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono-NL.ttf" style="font-size:1rem;font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * 1rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span role="button" tabindex="0" data-code="import SwiftUI
import FirebaseAnalytics

struct AnalyticsButtonView: View {
    var body: some View {
        Button(&quot;Press this &quot;) {
            // do something

            // log event with Firebase
            Analytics.logEvent(&quot;event_name&quot;, parameters: [&quot;param&quot;: 1])
            Analytics.setUserProperty(&quot;value&quot;, forName: &quot;name&quot;)
            Analytics.setUserID(&quot;user_id&quot;)
        }
    }
}" style="color:#f6f6f4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dracula-soft" style="background-color: #282A36" tabindex="0"><code><span class="line"><span style="color: #F286C4">import</span><span style="color: #F6F6F4"> </span><span style="color: #97E1F1; font-style: italic">SwiftUI</span></span>
<span class="line"><span style="color: #F286C4">import</span><span style="color: #F6F6F4"> </span><span style="color: #97E1F1; font-style: italic">FirebaseAnalytics</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F286C4">struct</span><span style="color: #F6F6F4"> </span><span style="color: #97E1F1; font-style: italic">AnalyticsButtonView</span><span style="color: #F6F6F4">: View {</span></span>
<span class="line"><span style="color: #F6F6F4">    </span><span style="color: #F286C4">var</span><span style="color: #F6F6F4"> body: </span><span style="color: #F286C4">some</span><span style="color: #F6F6F4"> View {</span></span>
<span class="line"><span style="color: #F6F6F4">        </span><span style="color: #97E1F1">Button</span><span style="color: #F6F6F4">(</span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">Press this </span><span style="color: #DEE492">&quot;</span><span style="color: #F6F6F4">) {</span></span>
<span class="line"><span style="color: #F6F6F4">            </span><span style="color: #7B7F8B">// do something</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F6F6F4">            </span><span style="color: #7B7F8B">// log event with Firebase</span></span>
<span class="line"><span style="color: #F6F6F4">            Analytics.</span><span style="color: #97E1F1">logEvent</span><span style="color: #F6F6F4">(</span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">event_name</span><span style="color: #DEE492">&quot;</span><span style="color: #F6F6F4">, </span><span style="color: #97E1F1">parameters</span><span style="color: #F6F6F4">: [</span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">param</span><span style="color: #DEE492">&quot;</span><span style="color: #F286C4">:</span><span style="color: #F6F6F4"> </span><span style="color: #BF9EEE">1</span><span style="color: #F6F6F4">])</span></span>
<span class="line"><span style="color: #F6F6F4">            Analytics.</span><span style="color: #97E1F1">setUserProperty</span><span style="color: #F6F6F4">(</span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">value</span><span style="color: #DEE492">&quot;</span><span style="color: #F6F6F4">, </span><span style="color: #97E1F1">forName</span><span style="color: #F6F6F4">: </span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">name</span><span style="color: #DEE492">&quot;</span><span style="color: #F6F6F4">)</span></span>
<span class="line"><span style="color: #F6F6F4">            Analytics.</span><span style="color: #97E1F1">setUserID</span><span style="color: #F6F6F4">(</span><span style="color: #DEE492">&quot;</span><span style="color: #E7EE98">user_id</span><span style="color: #DEE492">&quot;</span><span style="color: #F6F6F4">)</span></span>
<span class="line"><span style="color: #F6F6F4">        }</span></span>
<span class="line"><span style="color: #F6F6F4">    }</span></span>
<span class="line"><span style="color: #F6F6F4">}</span></span></code></pre></div>



<div style="height:48px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Now that you&#8217;ve successfully added a Swift Package to your Xcode project, you&#8217;re ready to leverage external libraries and frameworks to enhance your app&#8217;s functionality. Enjoy the benefits of modularity and maintainability that Swift Packages offer, and streamline your development process.</p>



<p><strong>Further Reading</strong></p>



<ul class="wp-block-list">
<li><a href="https://www.swiftyplace.com/blog/modular-code-with-swift-package-manager">How to Create Your First Package with Swift Package Manager</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://www.swiftyplace.com/blog/swift-package-manager-xcode">How to add third-party libraries in Xcode using Swift Package Manager</a> appeared first on <a rel="nofollow" href="https://www.swiftyplace.com">swiftyplace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.swiftyplace.com/blog/swift-package-manager-xcode/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: www.swiftyplace.com @ 2026-04-13 05:44:31 by W3 Total Cache
-->