Search code examples
ios-app-extensionios-frameworksswift-package-manager

Swift Embedded Framework That Depends on Swift Package


My iOS app follows the "Photos Extension" template: - A standalone, "container" app - A Photo Editing extension, which is deployed by embedding it within the app above.

As suggested by Apple, code that is shared by both the app and the extension is gathered in a "core" cocoa framework that is embedded in the app, and to which both the app and the extension are linked.

So my Xcode project contains three targets:

  • The Framework target,
  • The Photo Editing Extension target, which links to the Framework but does not embed it, and
  • The App target, that embeds the Extension binary and the Framework binary, and links to both.

So far, so good.


Furthermore, the framework, the app, and the extension depend on two libraries MyLibraryA and MyLibraryB I have on Github (and in turn, MyLibraryA depends on MyLibraryB).

I originally set the dependency on MyLibraryA and MyLibraryB using Carthage, and everything was working fine.


Then, I decided to migrate my libraries A and B to Swift Packages.

I removed all Carthage-related settings in project and targets, framework search paths, etc. to make sure the Swift Package versions of my libraries are referenced and not the cached Carthage builds. I also deleted the Carthage directories (checkouts and build).

The Problem

When I build the shared/embedded Framework target, there are no issues.

But when I try to build either the App or App Extension targets, I get an error pointing to the shared frameworks Swift header (MyFramewor-Swift.h):

// ...
@import CoreGraphics;
@import CoreImage;
@import Foundation;
@import PhotosUI;
@import UIKit;
@import MyLibraryA;  <-- Module 'MyLibraryA' Not Found
// ...

And the resulting:

Could not build Objective-C module 'MyFramework'

I know frameworks that are distributed as binaries cannot depend on Swift packages, but this embedded framework is compiled locally from source code and then embedded.

Perhaps there are some changes I can make to my setup on Xcode to get it to work?

I tried changing Enable Modules (C and Objective-C) to No in the Build Settings for the Framework target, to no avail.


Solution

  • You can currently set Install Objective-C Compatibility Header to No in Build Settings for modules that require a Swift Package dependency.

    This's probably due to "Swift Packages" being "Swift", but still looks like a bug to me.