Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEALIUM SWIFT BUG]: Unable to preview a SwiftUI view when Tealium is integrated using SwiftPM #137

Closed
danielbyon opened this issue Mar 27, 2020 · 7 comments
Assignees
Labels
awaiting-confirmation awaiting confirmation of fix fix-version-1.9.4

Comments

@danielbyon
Copy link

Your Environment
Fill out as appropriate.
iOS Version(s) [e.g. 12.1]: tvOS 13
Xcode version [Xcode> About Xcode e.g. 10.1 (10B61)]: 11.3.1
Swift version [e.g. 4.2]: 5.2
Tealium Swift library version [e.g. 1.6.7]: 1.9.1
Dependency manager [None/Carthage/CocoaPods]: SwiftPM
Dependency manager version:

Describe the bug
I am trying to implement a SwiftUI view in my main tvOS app target, and while I can build the project normally, when building for a canvas preview, multiple errors occur across multiple Tealium targets.

Does a workaround exist?
No workaround, I tried moving the SwiftUI view to a separate framework that is imported by the app target, and also trying it as a separate SwiftPM package. It appears being in the same workspace/project that also integrates Tealium using SwiftPM results in this error.

To Reproduce

  1. Integrate Tealium in tvOS app using SwiftPM
  2. Set tvOS deployment target to at least 13.0
  3. Add a new SwiftUI View file, don't change anything
  4. Open the file, open the canvas, click Resume to build the preview

Expected behavior
Preview builds and shows the default Apple stub code for a SwiftUI view

Actual behavior
Preview fails to compile. Attached error log
Tealium SwiftUI errors.txt

Screenshots

Additional context
This could also occur on iOS, but since we don't yet set iOS 13 as the deployment target, we can't use SwiftUI on that platform so I didn't try.

I noticed that even though my SwiftUI view didn't import Tealium, Xcode still rebuilt all packages (including Tealium). This happens even when I tried to isolate my SwiftUI view in a separate SwiftPM local package that lived in the same project file.

Some of the errors relate to symbols not being available on tvOS, such as CLRegionState. The fix could possibly be to explicitly wrap those code blocks using #if os(iOS), that way SwiftPM knows not to compile that for tvOS. Also some errors relate to UNNotificationCenter APIs, which require tvOS 10 or newer, and I noticed the Package.swift file specifies tvOS 9.

@craigrouse
Copy link
Contributor

@danielbyon the Location module is only supported on iOS at present. Can you remove this from your tvOS target and try again? Swift PM doesn't have a way to have different modules specified for different platforms in the same Package.swift spec, unfortunately (though I will look into the conditional compilation option - I wasn't aware that was supported in Package.swift).

@danielbyon
Copy link
Author

We don't import the Location module in any of our app/framework targets, but it appears Xcode builds every target anyways

We import:

  • AppData
  • Attribution (iOS only)
  • Collect
  • Connectivity
  • Core
  • DeviceData (iOS only)
  • Lifecycle
  • Logger
  • VolatileData

@craigrouse
Copy link
Contributor

OK, thanks for the info. We'll take a look and see what's possible.

@danielbyon
Copy link
Author

I re-read your response, you can't do #if os(tvOS) blocks in the Package.swift file itself. What I meant was to add the conditional compilation directive in the code files directly. This is because, as you noted, SwiftPM does not allow for restricting a particular module to a subset of the Package.swift's declared platforms (i.e. only allowing Location on iOS). So I believe the code itself has to be #ifdef'ed to not compile on unsupported platforms.

@craigrouse
Copy link
Contributor

@danielbyon I'm with you now - thank you. Will get back to you shortly on this.

@craigrouse
Copy link
Contributor

@danielbyon The release is up now that includes this fix. Thanks again for the suggestion. It's a shame the #ifdef is necessary, but hopefully this might be improved in future SPM releases. The fact that the target builds fine and only fails when you do a SwiftUI preview definitely feels like an Xcode bug to me. I'll file a bug report with Apple and see if it gets anywhere.

@craigrouse craigrouse added fix-version-1.9.4 awaiting-confirmation awaiting confirmation of fix labels Apr 2, 2020
@danielbyon
Copy link
Author

Confirmed with a new SwiftUI project for both iOS/tvOS. Created the project, added tealium as a package dependency, and resumed the preview in the template ContentView.swift.

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-confirmation awaiting confirmation of fix fix-version-1.9.4
Projects
None yet
Development

No branches or pull requests

3 participants