Adding Local dependencies in XCode11 using SPM

Xcode 12

If you have a remote version of your package already in the project and want to work on a local. There are a few extra steps...

1. Make sure your local package's version is higher than the remote version

If you don't do that, it will continue to fetch the remote package

  1. Select your project in Project Navigator
  2. In the main window select Swift Packages
  3. Select the package you want to replace with a local and remove it
  4. Go to File > Swift Packages > Add Package Dependency...
  5. Drag the your local package folder to the package search bar and add the prefix file://
  6. Click on Next

Confirm that the minimum version is higher than the remote one.


Local Swift Package Manager(SPM)

[Dependency manager]

Key point is: file:// + git which you can use it in URL field

file://<path>
//e.g.
file:///Users/alex/Desktop/MyProject

Notes:

  • It works with git repository that is why please make sure that you committed your changes beforehand
  • when you add a SPM dependency File -> Swift Packages -> Add Package Dependency it is added into project -> Swift Packages and implicit dependency[About] is added to Frameworks, Libraries, and Embedded Content
  • when you committed new changes into framework do not forget File -> Swift Packages -> Update to Latest Package Versions

Product folder

<path_derived_data>/<randomizer>/Build/Products/Debug
//e.g.
/Users/alex/Library/Developer/Xcode/DerivedData/SPMExperiments-bmmqumztjedpekaajffnaegxzwzg/Build/Products/Debug

[Local CocoaPods]
[Local Carthage]


Yep, Xcode makes this rudimentary task unnecessary difficult.

The trick is simple, though: in the sheet that pops up when you select 'Add Package Dependency…', in the URL field, you can enter a file:// URL. e.g. drag the package's folder into that field, which will place the path in it - e.g. '/Users/me/Documents/myShinyPackage/', then stick 'file://' to the front of it, and you'll be able to proceed.

Addendum: as some folks note in the comments below, this is problematic if you share the project with others, unless you standardise on paths. For individual use, however, it's fine.


This is the way I did it :

  • Drag and drop your package folder (in my example "DataStructures") from the finder directly into the Frameworks group of your target. You will see that the dropped item take a brown folder color (you can use the arrow to "get into it").
  • Go to your project target page, in the "Framework and Libraries" click the "+" button. Your package should show up in the "Workspace" area as a library.

enter image description here