Hello, I'm facing a problem in an Xcode project and a local package, where
#if canImport() does not behave as I would expect.
I have a local package named
GraphQL in which I put all kind of types related to a specific feature (here, the GraphQL models generated by the Apollo library).
This package is linked into the application target, with great success.
I do not want this package to be used from my unit tests target. These are unit tests, not integration or end-to-end tests: those tests do not connect to any GraphQL server. I do not want to drag in this test target dependencies it does not need. The
GraphQL local package is thus NOT linked into the test target.
There are places where I need
#if canImport(GraphQL), so that files can compile both with and without the GraphQL package. The code wrapped inside this conditional can not be moved into a distinct file (it sometimes requires access to fileprivate apis).
Unfortunately, Xcode compiles code guarded by
#if canImport(GraphQL), even in the unit test target which does not link against the GraphQL package. As expected, the test target won't build.
With Xcode 13.1, this problem would be transient, and an inconvenient
Product > Clean Build Folder would fix the problem.
With Xcode 13.2 RC, the problem will just not go away, and the project is unusable.
Do you happen to know this situation, and maybe a workaround?