Managing repo-relative Objective C imports

Is there a good way to manage Objective C imports across the different Swift Package Manager incarnations?

I've been settling on repo-relative imports since that seems to be good way to make Objective C library code portable across CocoaPods, swift build, swift test and inclusion in app projects via Xcode's Swift Package Manager interface.

After the testing suggestion at SwiftPM and Library Unit Testing - #9 by NeoNacho, I'm also trying swift package generate-xcodeproj and that doesn't seem to work:

For the other Swift Package Manager incarnations, accessing repo-relative headers works by adding .headerSearchPath("../.."), to the target where the path is a relative path from the path: to the repo root. With swift package generate-xcodeproj, I start to get the right paths if I add .headerSearchPath("${SOURCE_ROOT}"),. However, then I run into build failures since modules seem to be disabled in the swift package generate-xcodeproj while they're required in the other build.

I'll keep working through this, but it feels like I might have taken a wrong turn and curious if there's a better way.

See source at firebase-ios-sdk/Package.swift at master · firebase/firebase-ios-sdk · GitHub

Just to clarify this, you don't need to use generate-xcodeproj to be able to use xcodebuild, you can use it directly with packages since Xcode 11.

Thanks, would you clarify a bit more?

My understanding is that xcodebuild requires an Xcode project. How should the Xcode project be generated?

How can I get an Xcode target and scheme for the testTarget's in the Package.swift?

If I import the Swift Package to an app Xcode project, none of the packages test targets are visible in the Target list or Scheme manager.

You don't need an Xcode project, Xcode 11+ natively understands your package. You can create schemes by opening the package in Xcode (e.g. by just double-clicking the Package.swift manifest file), but most likely you won't need them and can use the autogenerated ones. Running xcodebuild -list in the directory which contains your package manifest will show which schemes are available, just like it would for an Xcode project.

1 Like

Perfect. Thanks! Nice and easy! :grin: