{"id":596,"date":"2024-01-31T15:29:30","date_gmt":"2024-01-31T14:29:30","guid":{"rendered":"https:\/\/sii.ua\/blog\/?p=596"},"modified":"2024-02-16T09:34:33","modified_gmt":"2024-02-16T08:34:33","slug":"quick-and-simple-modularising-your-project-with-swift-packages-up-to-date-with-xcode-13-2-1","status":"publish","type":"post","link":"https:\/\/sii.ua\/blog\/en\/quick-and-simple-modularising-your-project-with-swift-packages-up-to-date-with-xcode-13-2-1\/","title":{"rendered":"Quick and Simple Modularising your project with Swift Packages. Up to date with Xcode 13.2.1"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/www.swift.org\/package-manager\/\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >Swift Package Manager<\/a> is a tool for managing the distribution of Swift code. It\u2019s great to break down a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monolithic_application#:~:text=In%20software%20engineering%2C%20a%20monolithic,independent%20from%20other%20computing%20applications.\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >monolithic application<\/a> into modules.<\/p>\n\n\n\n<p> This process can increase the readability of your project as well as the compilation time of the code, as you don\u2019t need to compile the entire project to work on the single Swift Package module.<\/p>\n\n\n\n<p>In this article, you will learn <strong>how to create Swift Package in the fastest and simplest way<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Local Swift Package<\/h2>\n\n\n\n<p>For purpose of this tutorial, I created a basic project called <a href=\"https:\/\/github.com\/LooseMarek\/SwiftPackageTutorial\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >SwiftPackageTutorial<\/a>. This will be the main project, where you will create your local Swift Package. In the next step, you will extract it to a separate repository.<\/p>\n\n\n\n<p>First, inside your main project, create a new group called <strong>Modules<\/strong>. This will be the location for all your local modules.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Note:<\/strong> This step is not mandatory. You can add your Swift Package to any location within your project. However, if you are planning to have more than one Swift Package and keep all locally (without migrating them to separate repositories), this may help to keep your code more organized.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_01.png\"><img decoding=\"async\" width=\"384\" height=\"617\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_01.png\" alt=\"Choosing: New Group\" class=\"wp-image-599\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_01.png 384w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_01-187x300.png 187w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><\/figure>\n\n\n\n<p><br>Now, the simplest way to create a Swift Package inside your project is by going to <strong>File =&gt; New =&gt; Package\u2026<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_02.png\"><img decoding=\"async\" width=\"666\" height=\"357\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_02.png\" alt=\"Choosing: File - New - Package\" class=\"wp-image-601\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_02.png 666w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_02-300x161.png 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/a><\/figure>\n\n\n\n<p><br>This will open a new Xcode window with the prompt to choose the name and location for your Swift Package. For this example, you can name the package <strong>MyFirstSwiftPackage<\/strong> and select your <strong>Modules<\/strong> directory. You will also need to choose your main project <strong>SwiftPackageTutorial<\/strong> (or workspace if you are using one) from the <strong>Add to<\/strong> dropdown and <strong>Modules<\/strong> group from <strong>Group<\/strong> dropdown. Click <strong>Create<\/strong> to finish.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_03.png\"><img decoding=\"async\" width=\"849\" height=\"531\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_03.png\" alt=\"Choosing: Modules\" class=\"wp-image-603\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_03.png 849w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_03-300x188.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_03-768x480.png 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><\/figure>\n\n\n\n<p><br>To link the newly created Swift Package with your main project, select your project\u2019s main target (<strong>SwiftPackageTutorial<\/strong>) and under the <strong>General<\/strong> tab scroll to the <strong>Frameworks, Libraries, and Embedded Content<\/strong> section.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04.png\"><img decoding=\"async\" width=\"1024\" height=\"391\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04-1024x391.png\" alt=\"Choosing: SwiftPackageTutorial\" class=\"wp-image-605\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04-1024x391.png 1024w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04-300x114.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04-768x293.png 768w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_04.png 1172w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><br>Press plus (\u201c+\u201d) button, choose <strong>MyFirstSwiftPackage<\/strong> static library and press <strong>Add<\/strong> to finish.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_05.png\"><img decoding=\"async\" width=\"406\" height=\"464\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_05.png\" alt=\"Choosing: MyFirstSwiftPackage\" class=\"wp-image-607\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_05.png 406w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_05-263x300.png 263w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/a><\/figure>\n\n\n\n<p><br>Well done! You finished creating the first Swift Package. Just make sure if everything works fine.<\/p>\n\n\n\n<p>To test if you can use your local Swift Package, open the main struct from the <strong>MyFirstSwiftPackage<\/strong> module and replace<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\npublic private(set) var text = &quot;Hello, World!&quot;\n<\/pre><\/div>\n\n\n<p>with<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\npublic private(set) var text = &quot;Hello, World from Swift Package!&quot;\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_06.png\"><img decoding=\"async\" width=\"795\" height=\"280\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_06.png\" alt=\"Changing: Hello, World with Hello, World from Swift Package\" class=\"wp-image-609\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_06.png 795w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_06-300x106.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_06-768x270.png 768w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/a><\/figure>\n\n\n\n<p><br>Next (if you are using SwiftUI) go to your main project\u2019s <strong>ContentView<\/strong> struct and replace<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\nText(&quot;Hello, world!&quot;)\n<\/pre><\/div>\n\n\n<p>with<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\nText(MyFirstSwiftPackage().text)\n<\/pre><\/div>\n\n\n<p>Don\u2019t forget to also add <strong>import MyFirstSwiftPackage<\/strong> on top of your file.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_07.png\"><img decoding=\"async\" width=\"938\" height=\"367\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_07.png\" alt=\"Adding import MyFirstSwiftPackage on top of your file\" class=\"wp-image-611\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_07.png 938w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_07-300x117.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_07-768x300.png 768w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/a><\/figure>\n\n\n\n<p><br>Press run or reload the preview. You should now see the text saying <strong>&#8220;Hello, World from Swift Package!&#8221;.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_08.png\"><img decoding=\"async\" width=\"360\" height=\"753\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_08.png\" alt=\"Screen with the text:Hello, World from Swift Package\" class=\"wp-image-613\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_08.png 360w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/create_local_spm_08-143x300.png 143w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Moving Local Swift Package to Remote<\/h2>\n\n\n\n<p>Ok, so now you have your local Swift Package included in your project. You added a bunch of files to it that create your module, but let&#8217;s say, you are starting a new project where you would like to reuse that module. In just a few steps, you can extract your local Swift Package into a standalone module hosted on a separate repository.<\/p>\n\n\n\n<p>The easiest method to separate your local Swift Package from the project is to select the package in Xcode\u2019s project navigator panel and drag it to the desired location in Finder.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Important:<\/strong> While dragging your local Swift Package from Xcode, it\u2019s important to press and hold the option key. This will create a copy of the package as opposed to moving it to a different location.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_01.png\"><img decoding=\"async\" width=\"279\" height=\"282\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_01.png\" alt=\"Creating a copy\" class=\"wp-image-615\"\/><\/a><\/figure>\n\n\n\n<p><br>You can now double-click the <strong>Package.swift<\/strong> file from the <strong>MyFirstSwiftPackage<\/strong> to open it in Xcode.<\/p>\n\n\n\n<p>In Xcode, go to <strong>Source Control =&gt; New Git Repositories<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02.png\"><img decoding=\"async\" width=\"848\" height=\"368\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02.png\" alt=\"Choosing: New Git Repositories\" class=\"wp-image-617\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02.png 848w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02-300x130.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02-768x333.png 768w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_02-370x162.png 370w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/a><\/figure>\n\n\n\n<p><br>Keep <strong>MyFirstSwiftPackage<\/strong> checked and press <strong>Create<\/strong> to finish.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_03.png\"><img decoding=\"async\" width=\"561\" height=\"374\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_03.png\" alt=\"Creating Git repositories for projects\" class=\"wp-image-619\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_03.png 561w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_03-300x200.png 300w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/a><\/figure>\n\n\n\n<p><br>This will create a local repository with the <strong>main<\/strong> branch.<\/p>\n\n\n\n<p>Now you can create or link a local repository with remote in any way you like \u2013 it can be through Terminal, any third-party software, or in Xcode. To finish this chapter, I will demonstrate the process when using Xcode.<\/p>\n\n\n\n<p>In your left-hand panel, select <strong>Show the Source Control Navigation<\/strong> tab (second from the left), and then <strong>Repositories<\/strong> sub-tab. Right-click on the package name <strong>MyFirstSwiftPackage<\/strong> to show more options and then press the <strong>New \u201cMyFirstSwiftPackage\u201d remote\u2026 <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_04.png\"><img decoding=\"async\" width=\"410\" height=\"469\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_04.png\" alt=\"Choosing: New \" class=\"wp-image-621\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_04.png 410w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_04-262x300.png 262w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/a><\/figure>\n\n\n\n<p><br>For this example, I\u2019m using a GitHub account for hosting my remote repositories.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_05.png\"><img decoding=\"async\" width=\"488\" height=\"426\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_05.png\" alt=\"Description: Used for Tutorial with SwiftPackageTutorial\" class=\"wp-image-623\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_05.png 488w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/moving_local_spm_to_remote_05-300x262.png 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Note:<\/strong> If you don\u2019t have GitHub configured in Xcode, you will need to create Personal Access Token from your GitHub Account under <strong>Settings =&gt; Developer settings =&gt; Personal access tokens<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Replacing Local Swift Package with Remote<\/h2>\n\n\n\n<p>Great! Now your Swift Package is in a separate repository. It\u2019s time to replace your local version in the project with the remote version.<\/p>\n\n\n\n<p>Go back to the <strong>SwiftPackageTutorial<\/strong> project and remove the local version of the <strong>MyFirstSwiftPackage <\/strong>from Project Navigation in Xcode<strong>. <\/strong>If you don\u2019t have any other modules in the <strong>Modules<\/strong> group, you can also remove the folder.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_01.png\"><img decoding=\"async\" width=\"465\" height=\"404\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_01.png\" alt=\"Choosing: Modules\" class=\"wp-image-625\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_01.png 465w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_01-300x261.png 300w\" sizes=\"(max-width: 465px) 100vw, 465px\" \/><\/a><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Note:<\/strong> Make sure you press <strong>Move to Trash<\/strong> <em>not<\/em> <strong>Remove Reference<\/strong> as you want to completely remove it from the repository.<\/li>\n<\/ul>\n\n\n\n<p>Don\u2019t forget to remove the linked static library. Go to your project\u2019s main target (<strong>SwiftPackageTutorial<\/strong>), and under the <strong>General<\/strong> tab scroll to the <strong>Frameworks, Libraries, and Embedded Content<\/strong> section. Select <strong>MyFirstSwiftPackage<\/strong> and press the minus (\u201c-\u201d) button.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02.png\"><img decoding=\"async\" width=\"1024\" height=\"386\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02-1024x386.png\" alt=\"Selecting MyFirstSwiftPackage and pressing the minus (\u201c-\u201d) button\" class=\"wp-image-627\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02-1024x386.png 1024w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02-300x113.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02-768x290.png 768w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_02.png 1174w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><br>Don\u2019t worry about the errors related to the missing module <strong>MyFirstSwiftPackage<\/strong> as you will fix it in a minute.<\/p>\n\n\n\n<p>Press <strong>File =&gt; Add Packages\u2026<\/strong> to open prompt with all available Swift Packages.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_03.png\"><img decoding=\"async\" width=\"428\" height=\"192\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_03.png\" alt=\"Choosing: Add Packages\" class=\"wp-image-629\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_03.png 428w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_03-300x135.png 300w\" sizes=\"(max-width: 428px) 100vw, 428px\" \/><\/a><\/figure>\n\n\n\n<p><br>In the top-right corner, you will find the <strong>Search or Enter Package URL<\/strong> input. Copy-paste the URL of your Swift Package. <a href=\"https:\/\/github.com\/LooseMarek\/MyFirstSwiftPackage\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >Here you will find the tutorial<\/a>.<\/p>\n\n\n\n<p>Since you haven\u2019t added any version tags to the package, you can keep the default configurations for the <strong>Dependency Rule<\/strong> which is <strong>Branch =&gt; main<\/strong>, but if you added version tag already, the recommended rule is <strong>Up to Next Major Version<\/strong> (and selecting the latest version).<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04.png\"><img decoding=\"async\" width=\"1024\" height=\"573\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04-1024x573.png\" alt=\"Choosing: Dependency Rule\" class=\"wp-image-631\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04-1024x573.png 1024w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04-300x168.png 300w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04-768x430.png 768w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04-555x312.png 555w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_04.png 1087w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><br>Press <strong>Add Package<\/strong> which will show you the list of available products included in the package. Keep it as is, and press <strong>Add Package <\/strong>again to finish.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_05.png\"><img decoding=\"async\" width=\"661\" height=\"304\" src=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_05.png\" alt=\"Choosing: Add Package\" class=\"wp-image-633\" srcset=\"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_05.png 661w, https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/replacing_local_spm_with_remote_05-300x138.png 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/a><\/figure>\n\n\n\n<p><br>The good news is, that this will automatically add the package to <strong>Frameworks, Libraries, and Embedded Content<\/strong> so you don\u2019t need to do it yourself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Congrats! You now have your Swift Package hosted on the remote repository and you can use it in your main project. To verify it, you can refresh the preview or run the project and Xcode should no longer show any errors related to the missing module <strong>MyFirstSwiftPackage<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Resources<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.swift.org\/package-manager\/\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >Swift Package Manager<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Monolithic_application#:~:text=In%20software%20engineering%2C%20a%20monolithic,independent%20from%20other%20computing%20applications\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >Monolithic<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/LooseMarek\/SwiftPackageTutorial\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >SwiftPackageTutorial project example<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/LooseMarek\/MyFirstSwiftPackage\" target=\"_blank\" rel=\"noopener\" title=\"\" rel=\"nofollow\" >MyFirstSwiftPackage Swift Package example<\/a><\/li>\n<\/ul>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;596&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;2&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;5\\\/5&quot;,&quot;size&quot;:&quot;30&quot;,&quot;title&quot;:&quot;Quick and Simple Modularising your project with Swift Packages. Up to date with Xcode 13.2.1&quot;,&quot;width&quot;:&quot;159&quot;,&quot;_legend&quot;:&quot;{score}\\\/5&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 159px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 2px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 30px; height: 30px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 24px;\">\n            5\/5    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Swift Package Manager is a tool for managing the distribution of Swift code. It\u2019s great to break down a &hellip; <a class=\"continued-btn\" href=\"https:\/\/sii.ua\/blog\/en\/quick-and-simple-modularising-your-project-with-swift-packages-up-to-date-with-xcode-13-2-1\/\">Continued<\/a><\/p>\n","protected":false},"author":24,"featured_media":597,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[102],"class_list":["post-596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hard-development","tag-software-development"],"acf":[],"aioseo_notices":[],"featured_media_url":"https:\/\/sii.ua\/blog\/wp-content\/uploads\/2024\/01\/Quick-and-Simple-Modularising-your-project-with-Swift-Packages.-Up-to-date-with-Xcode-13.2.1.jpg","category_names":["Hard development"],"_links":{"self":[{"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/posts\/596"}],"collection":[{"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/comments?post=596"}],"version-history":[{"count":2,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/posts\/596\/revisions"}],"predecessor-version":[{"id":636,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/posts\/596\/revisions\/636"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/media\/597"}],"wp:attachment":[{"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/media?parent=596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/categories?post=596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sii.ua\/blog\/en\/wp-json\/wp\/v2\/tags?post=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}