# Possible to use SPM packages from Cocoapods' "Pods" project?

**URL:** <https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187>\
**Category:** Using Swift\
**Tags:** packagemanager, cocoapods\
**Created:** [October 30, 2021, 10:48pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187 "2021-10-30T22:48:43Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [October 30, 2021, 10:48pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/1 "2021-10-30T22:48:43Z")

</div>

Scenario: I am developing two frameworks, FLEX and Reflex. FLEX has no dependencies and Reflex depends on FLEX and Echo, a swift package. Both FLEX and Reflex support either SPM or Cocoapods. `Echo` only supports SPM and it also depends on swift-atomics. FLEX is purely Objc and Reflex is Swift.

In an example app, I added FLEX and Reflex as pod dependencies. After opening the generated workspace, I added Echo as a Swift package to the `Pods` project, to the `Reflex` target. I have tried this all with and without the `use_frameworks!` option in the `Podfile`.

 ![Workspace](https://global.discourse-cdn.com/swift/original/3X/8/9/89775acba6a3941429da2d37fe0cc72e786976fe.png)

![Linker](https://global.discourse-cdn.com/swift/original/3X/9/0/90d73db952f94bcf8f901391bd09f9e1d9eebd63.png)

Everything builds up until it reaches `import Echo` in Reflex. `No such module 'Echo'` it tells me. Which is strange, because I can `import CEcho` just fine, where `CEcho` is one of the targets declared by `Echo`…

What do I need to do to get this to work? I've tried everything I can think of, but I'm really just guessing here; package management and build systems aren't my strong-suit.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [October 31, 2021, 9:32am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/2 "2021-10-31T09:32:52Z")

</div>

You best bet is to keep the SPM and CocoaPods dependency chains separate, so you'll need to make Echo and `swift-atomics` visible to CocoaPods if you want your overall framework to be compatible. I'd suggest you focus on getting your SPM case working first, then moving on to CocoaPods. Unfortunately, `swift-atomics` doesn't support CocoaPods, so you'll need your own Podspec for it.

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [October 31, 2021, 5:19pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/3 "2021-10-31T17:19:44Z")

</div>

The reason I'm not using them all from SPM is because it's a huge pain to develop them from within SPM. Local packages aren't editable so you have to edit them in separate windows and then "update" the packages in a separate project.

But Xcode doesn't properly re-fetch package dependencies, even when you clear the cache; it just re-fetches the same commit, even if the chosen branch is on a new commit. The only way to make it download the new commit is to remove the dependencies, quit Xcode, clear derived data, and add them back. Gotta do this any time you want to test some changes in an app. It's a truly awful experience.

If I can't get SPM+Cocoapods working together, I'll have throw them all into a project by hand 😣 Which I don't want to do. (That, or make podspecs for them both, which is even more work) There's no reason why this shouldn't work!

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [November 1, 2021, 1:42am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/4 "2021-11-01T01:42:42Z")

</div>

Finally got "show in log" to work (it wasn't working before) and I'm seeing one invocation of `-fmodule-map-file` for every module _except_ Echo, for some reason. This explains why I'm able to import `CEcho`, but not `Echo` itself. I don't know how to fix this, though.

cc @Alejandro and @NeoNacho :(

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [November 1, 2021, 10:17am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/5 "2021-11-01T10:17:59Z")

</div>

You can put the packages in a workspace to make them editable and work alongside them (see a [post I wrote here](https://www.timc.dev/posts/editing-swift-packages/))

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [November 1, 2021, 4:33pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/6 "2021-11-01T16:33:11Z")

</div>

That's news to me! Cool! However, I can't run Xcode 13 so I can't use the fancy new app targets… :(

I need to be able to edit and _run_ them together in an app. Cocoapods supports this use case perfectly

---

<div class="post-metadata">

**Author:** ![wowbagger](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/wowbagger/32/13847_2.png) [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Post date:** [November 1, 2021, 11:48pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/7 "2021-11-01T23:48:11Z")

</div>

> [@NSExceptional](#):
>
> Local packages aren't editable so you have to edit them in separate windows and then "update" the packages in a separate project.

> [@0xTim](#):
>
> You can put the packages in a workspace to make them editable and work alongside them (see a [post I wrote here](https://www.timc.dev/posts/editing-swift-packages/))

It's also possible to edit local dependencies (and cache of remote dependencies, I think) without putting them in the workspace if the root project is a SwiftPM project:

 ![Screen Shot 2021-11-02 at 07.44.21](https://global.discourse-cdn.com/swift/original/3X/7/f/7f57fc9380ed817e38d004c5335b78c59d64b34c.png)

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [November 1, 2021, 11:53pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/8 "2021-11-01T23:53:25Z")

</div>

You definitely cannot edit any dependencies at all in the "Package Dependencies" section. I'm not able to, anyway. Either way, it doesn't matter since even local dependencies are always copied and never simply referenced as they probably should be. :/

---

<div class="post-metadata">

**Author:** ![wowbagger](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/wowbagger/32/13847_2.png) [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Post date:** [November 2, 2021, 12:14am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/9 "2021-11-02T00:14:33Z")

</div>

hmm it appears that local dependencies are simply referenced for me:

My change (appended extra "!"s) to the dependency in the "Package Dependencies" section

 ![Screen Shot 2021-11-02 at 08.06.59](https://global.discourse-cdn.com/swift/original/3X/c/3/c3ac5f6c30e4b237d2dd776102f350d936192402.png)

is reflected in the dependency package itself:

 ![Screen Shot 2021-11-02 at 08.08.10](https://global.discourse-cdn.com/swift/original/3X/4/d/4de680980e382ed70bc137bc72f685ae3aae558d.png)

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [November 2, 2021, 2:30pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/10 "2021-11-02T14:30:13Z")

</div>

If you right click on the package and "show in finder", does it take you somewhere in DerivedData?

---

<div class="post-metadata">

**Author:** ![wowbagger](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/wowbagger/32/13847_2.png) [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Post date:** [November 2, 2021, 11:46pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/11 "2021-11-02T23:46:33Z")

</div>

It takes me directly to where the dependency package is located, _not_ in DerivedData.

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [November 5, 2021, 12:06am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/12 "2021-11-05T00:06:47Z")

</div>

Interesting… I guess if it behaves differently when it's a swift package instead of an Xcode project? Good to know. Unfortunately that doesn't help me since this is an Xcode project :/

---

<div class="post-metadata">

**Author:** ![bielikb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bielikb/32/2996_2.png) [@bielikb](https://forums.swift.org/u/bielikb)\
**Post date:** [November 5, 2021, 2:01pm UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/13 "2021-11-05T14:01:50Z")

</div>

> [@NSExceptional](#):
>
> But Xcode doesn't properly re-fetch package dependencies, even when you clear the cache; it just re-fetches the same commit, even if the chosen branch is on a new commit. The only way to make it download the new commit is to remove the dependencies, quit Xcode, clear derived data, and add them back. Gotta do this any time you want to test some changes in an app. It's a truly awful experience.

Xcode:  
_File -\> Packages -\> Update to latest package versions_ should do the trick.

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [March 13, 2022, 6:34am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/14 "2022-03-13T06:34:48Z")

</div>

I know it's been a while but I just ran into this again and I wanted to say how incredibly misleading the labels are. The "reset cache" and "update to latest" buttons seem like they're backwards almost. What does invalidating the package cache even do if it doesn't re-fetch whatever branch or version you specified? :P

---

<div class="post-metadata">

**Author:** ![sekitaka](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sekitaka/32/29769_2.png) [@sekitaka](https://forums.swift.org/u/sekitaka)\
**Post date:** [April 28, 2023, 12:23am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/16 "2023-04-28T00:23:11Z")

</div>

> [@NSExceptional](#):
>
> This explains why I'm able to import `CEcho`, but not `Echo` itself. I don't know how to fix this, though.

@NSExceptional Hi, did you find any solution? I have same problem now.  
I'm trying to use Amplify that is installed by SPM in pod project. But I got "No such module 'Amplify'".

---

<div class="post-metadata">

**Author:** ![NSExceptional](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nsexceptional/32/6813_2.png) [@NSExceptional](https://forums.swift.org/u/NSExceptional)\
**Post date:** [December 19, 2023, 12:37am UTC](https://forums.swift.org/t/possible-to-use-spm-packages-from-cocoapods-pods-project/53187/17 "2023-12-19T00:37:20Z")

</div>

I have not touched this project since then, I'm sorry. The maintainer of Echo and CEcho has all but abandoned his OSS work and has been slow to respond since he got a job at Apple.
