SwiftUI previews fix#1066
Conversation
|
@TizianoCoroneo: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
|
Hey thank you for doing this! I think you’re being slightly too aggressive adding it to every file - it should really only be the files I marked with It does seem to be a combo SPM/SwiftUI bug that this lib gets compiled for SwiftUI even when it’s not a dependency of the target being compiled though. Will file a radar on that one. |
…prevent compilation on other platforms. This previously caused an issue that prevented SwiftUI previews on iOS targets from working properly, if that target included Apollo as a dependency.
854b7f7 to
f7711c7
Compare
|
I removed the extra |
|
Awesome, thanks so much for this! |
Hello @designatednerd 👋
Thank you for your amazing work on this library! I had the same issue reported here and decided to try to help out.
This PR fixes an issue that started with the inclusion of
ApolloCodegenLibin0.23.0, where all SwiftUI previews for files in targets that also import Apollo stopped working with the following error:In my case, I have Apollo as a dependency using SPM. I don't know if this issue is reproducible with cocoapods or other dependency managers.
This happens because
ApolloCodegenLibis meant to be built only on macOS, and this check is only enforced with a runtime@availableannotation instead of a compile-time#if os(macOS).I looked for a way to specify a specific platform per-target directly in the SPM manifest, but according to this PR in the SPM repo there is no way for now (and he recommends to strip away the platform specific code using
#if):This PR applies the suggestion specified above. I'm sorry it is not below 20 lines and I'm not really following the contributor guide, but this seems an "innocuous" bug fix. 😄
I don't know how to test this behavior with SwiftUI previews to be honest.