Swift Package-generated Xcode project doesn't include resources

Apple Recommended

Replies

I also had problems with resources visibility in SPM package with generated project file. And I've found out that if you don't generate Xcode Project file for the package but open package folder with Xcode instead there are no errors with Bundle.module and you even can see generated code for searching your module resources by CTRL+CMD+Click on .module. Also there won't be any problems with visible folders since Xcode shows all folder files.

Do you have any particular reason for project file generation? I think in most cases open a folder will be enough.
We have SwiftUI files which will not preview without a target. In this case, opening the package directly as a folder through Xcode is not sufficient.
Hello, we have the same problem with Bundle.module not accessible when opening our xcodeproj but requires it for our CI and other convenience tools as SwiftLint. Did you guys find any solution / workaround?

Still a little bit hard to know if this possibility was planned or not as Bundle.module is generated by SPM not Xcode.
zocario - we have a demo app that uses our package and have created a workspace containing the demo project and the package. We are also using SwiftLint and have opted to run the linter when building the demo app target. We mostly work from this workspace so it is sufficient for our needs.

We have recently discovered that having dependencies on a package breaks SwiftUI previews in that package. There is a radar for this bug already. It seems that having a project should not be necessary for those previews to work, so my first reply in this thread can be ignored.

If you find a way to get this working with your CI please let us know
Thanks jeff97 for the details, I've filled a bug report (FB8089986) that you can see on open radar (I don't know why but I can't add the link it this post). We'll see - if by chance they answer - if this is a bug / known issue.. did you create a bug report on your side?
Still facing the same issue here using Xcode 12 final version. As anyone come up with a solution?
I was told that the function to generate an Xcode project predates support for resources and thus doesn’t add the building of resource bundles.
Me too.

Only swift package preview can not run code with "requestAuthorization"...
So I need a xcode project target.
Is there any update to this? I'm having the same problem
Are there any plans to support this functionality in the future?

That happens because generated project do not contain resources in build phase. So generate-xcodeproj is deprecated and you need to implement copying resources on your own.

For anyone still facing this problem, the workaround I've been using is to define Bundle.module when compiling from Xcode.

import Foundation

// MARK: - BundleFinder

// when compiled from xcodeproj, this code is necessary for bundling resources
// but when compiling as a swift package, these cause compilation errors: "redefinition of `module`".
// The XCODE_COMPILE pre-processor flag is set in the xcodeproj settings and is only present
// when the code is compiled from Xcode (or xcodebuild)
#if XCODE_COMPILE
 private class BundleFinder {}

 extension Bundle {
  static var module = Bundle(for: BundleFinder.self)
 }
#endif

Creating a flag XCODE_COMPILE in the Active Compilation Conditions (for release and debug) for your xcodeproj build settings allows your project to compile when using Xcode/xcodebuild while at the same time not breaking your swift package w/ a redefinition of Bundle.module.