# Making dependencies writable in Xcode package project

**URL:** <https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090>\
**Category:** Using Swift\
**Tags:** spm, xcode\
**Created:** [November 25, 2019, 12:35am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090 "2019-11-25T00:35:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [November 25, 2019, 12:35am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/1 "2019-11-25T00:35:25Z")

</div>

I'm using Xcode to develop an SPM-based executable, and I’ve run into a situation where I’d like to be able to edit the source code of one of my dependencies. Xcode conveniently lets me navigate to the dependency’s source files, but seems to make them read-only.

This particular dependency comes from Github. I’d like to fork that project and start adding to it, but it would be most useful if I could do it directly in Xcode, and have Xcode rebuild the dependency as needed each time I run.

Is this possible?

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [November 25, 2019, 4:11am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/2 "2019-11-25T04:11:52Z")

</div>

> [@JetForMe](#):
>
> Is this possible?

Yes: make a local clone of the package you want to edit, and drag its folder into the project navigator on the side bar. Xcode will understand that it is an editable version of one of the packages listed in the project.

 ![55](https://global.discourse-cdn.com/swift/original/2X/5/5deb190277357a3c8c15fde2bdad5893968b5c85.jpeg)

---

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [November 25, 2019, 5:04am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/3 "2019-11-25T05:04:46Z")

</div>

So, my package project doesn't have the typical project at the top of the Files & Groups view.

 ![23%20](https://global.discourse-cdn.com/swift/original/2X/0/027fa295d42dd8b5ae3a4b65557b8f32ad61b00a.png)

---

<div class="post-metadata">

**Author:** ![gwendal.roue](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gwendal.roue/32/13992_2.png) [@gwendal.roue](https://forums.swift.org/u/gwendal.roue)\
**Post date:** [November 25, 2019, 5:18am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/4 "2019-11-25T05:18:08Z")

</div>

Oops. Did you try anything? Including checking the editing options provided by SPM itself? [swift-package-manager/Usage.md at main · apple/swift-package-manager · GitHub](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#editing-a-package)

---

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [November 25, 2019, 5:31am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/5 "2019-11-25T05:31:31Z")

</div>

Oh, thanks for pointing that out, that's a helpful feature. Issuing `swift package edit SDL --branch additions` created a new `Packages` directory and put a copy of the dependency there, switched to the branch `additions`. Unfortunately, Xcode doesn't seem to see it, refusing to show the sources there (it still shows the sources down inside `DerivedData/.../checkouts`, but that's still read-only).

Note that the `Packages` entry in Xcode is a blue folder, which usually indicates a folder reference rather than a group, and which normally reflects its contents as on disk. However, in the inspector you can see that the path for that folder reference is `…DerivedData/InfoDisplay-bbxdotrtztwikhbjrfwwtbkoypav/SourcePackages/checkouts/SDL`, not `$(PROJECT_DIR)/Packages`. This seems like a bug to me.

(It also didn't change the `Package.swift` github URL to refer to the `additions` branch, but I'm not sure if it was supposed to or not.)

Xcode:

 ![06%20](https://global.discourse-cdn.com/swift/original/2X/8/80aef07236eda5d8a21c49b2ce4192619bdaf0ac.png)

Finder:

![08%20](https://global.discourse-cdn.com/swift/original/2X/e/e1744ed450067ddccbc20434bf2651c5757215bf.png)

---

<div class="post-metadata">

**Author:** ![Spencer\_Kohan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spencer_kohan/32/4505_2.png) [@Spencer\_Kohan](https://forums.swift.org/u/Spencer_Kohan)\
**Post date:** [November 25, 2019, 11:18am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/6 "2019-11-25T11:18:06Z")

</div>

The CLI driven workflow has good handling of this use-case. You can create your package with:

```
$ swift package init --type executable

```

Then add your dependencies, and [make them editable](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#editing-a-package)

Now you can make your xcode project:

```
$ swift package generate-xcodeproj

```

And inside this xcode project, your dependency sources will appear as a group and the files will be editable.

It also works fine for local dependencies: i.e. if your dependency is declared with a relative path rather than a URL.

Just take care because the project is no longer portable: you'll have to make sure to push any changes you make in the dependency upstream.

---

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [November 25, 2019, 10:29pm UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/7 "2019-11-25T22:29:59Z")

</div>

That works, it creates an explicit Xcode project (unlike Xcode 11’s implicit project when opening a `Pacakge.swift` file), and it lets me edit the dependencies.

Is this, then, a bug in Xcode when looking at a non-pre-generated Package?

---

<div class="post-metadata">

**Author:** ![jonprescott](https://avatars.discourse-cdn.com/v4/letter/j/e36b37/32.png) [@jonprescott](https://forums.swift.org/u/jonprescott)\
**Post date:** [November 25, 2019, 11:17pm UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/8 "2019-11-25T23:17:55Z")

</div>

From what I gather from the WWDC videos, this is a deliberate design choice. For most uses of Xcode 11, Apple feels that imported packages by default should be read-only. You have to go through the process to make them editable.

I think there is a way to make a SPM project already added in Xcode as a dependency editable, but, I can't recall how right off the top of my head.

---

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [November 26, 2019, 1:44am UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/9 "2019-11-26T01:44:25Z")

</div>

This seems like a poor choice. Now we have two subtly different kinds of Swift Package Xcode project, with all the attendant confusion (as this thread points out).

---

<div class="post-metadata">

**Author:** ![monocularvision](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/monocularvision/32/1411_2.png) [@monocularvision](https://forums.swift.org/u/monocularvision)\
**Post date:** [November 12, 2024, 11:55pm UTC](https://forums.swift.org/t/making-dependencies-writable-in-xcode-package-project/31090/10 "2024-11-12T23:55:45Z")

</div>

For future folks finding this thread on Google, you _can_ accomplish what is desired here without the `generate-xcodeproj`, but it requires the creation of an empty `xcworkspace`. [Full details in this blog post](https://www.timc.dev/posts/editing-swift-packages/) but the TLDR is:

The TLDR:

1. Create an empty workspace
2. Draft the _containing folder_ of the Swift Package you want to work on
3. Wait for packages to resolve
4. Drag the _containing folder_ of the dependency you want to edit. The name of that folder needs to match the name of the dependency as it appeared after step 3. And make sure that it is a folder where you have the dependency checked out or is editable.
5. Wait for packages to resolve
6. Edit your current package _and the dependency_ all together.

Step #4 is tricky because you need to make sure to drag it to the _root_ of the workspace and not _into_ the package you added in #2. Xcode makes this hard.
