'Importing an "internal" cocoapod to a new SPM module?

I'm working on a legacy project that was built with Cocoapods.

We're trying to find a way to update the project iteratively to use SPM without having to make a "big bang" change to the whole project.

The Podfile defines multiple "targets" which are all added to the .xcworkspace as individual "sub-projects".

We have one "root" project which is the main app project.

I've added an Package.swift file with a very simple config like...

// swift-tools-version:5.5

import PackageDescription

let package = Package(
    name: "My-App",
        platforms: [.iOS(.v13)],
    products: [
            .library(name: "MyFeature", targets: ["MyFeature"]),
    ],
    dependencies: [
    ],
    targets: [
            .target(name: "MyFeature"),
    ]
)

This sits with the "root" project that I mentioned before.

So far this all looks like it should be working. The SPM module is used within some of the sub-projects but I can make that work by adding the "MyFeature" module in the sub-project's frameworks/libraries.

However... the new SPM module uses a type that is defined in one of the other sub-projects/internal cocoapods.

And Xcode seems to not be able to find the framework to import it even though it auto completes and can be imported in the "regular" project code.

The directory structure is like...

Root Dir
-> Package.swift
-> MainApp Dir
   -> MyApp.xcworkspace
   -> MyApp Dir
      -> MyApp.xcodeproj <- this is the "main app" target
   -> OtherFeature Dir
      -> OtherFeature.xcodeproj <- this is the "internal cocoapod" target I want to import
      -> OtherFeature Dir
         -> other feature code
-> Sources Dir
   -> MyFeature Dir
      -> my feature code... <- this is where the `import OtherFeature` doesn't work

Most of the sources I've found online cover using SPM and Cocoapods to distribute a framework but they don't cover using Cocoapods this way alongside SPM and I wondered if this was even possible.

Without that extra import it looks like it all should be working. If I can get this next hurdle toppled I feel like we will have cracked the problem.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source