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

Conditionally conform to Combine.TopLevelDecoder #132

Merged
merged 7 commits into from Oct 4, 2019
Merged

Conditionally conform to Combine.TopLevelDecoder #132

merged 7 commits into from Oct 4, 2019

Conversation

sharplet
Copy link
Contributor

This enables use of XMLDecoder with Combine's decode(_:decoder:) operator by conditionally conforming to TopLevelDecoder when Combine is available.

I explored doing the same for TopLevelEncoder, but XMLEncoder currently requires rootKey: to be specified at encoding time, so it's not possible to provide an implementation of encode(_:) without some design around how to dynamically determine the root key to use.

MaxDesiatov
MaxDesiatov previously approved these changes Sep 25, 2019
@MaxDesiatov
Copy link
Collaborator

@sharplet thank you for the PR! Would you mind adding a short example of use with Combine to README and also a unit test (maybe based on the example code)?

@sharplet
Copy link
Contributor Author

sharplet commented Sep 30, 2019

Added a test case and a new section to the README, let me know what you think!

@sharplet
Copy link
Contributor Author

Looks like the swiftpm tests are failing on CI, possibly because the Swift compiler version isn't recent enough to know about the macCatalyst platform? I could add a #if !os(Linux) conditional to the new test case, which feels a little clunky but should work.

@sharplet
Copy link
Contributor Author

One other option would be to just drop macCatalyst from the availability annotation. I've pushed a commit which explicitly excludes Linux, in case you're happy with that option.

This shouldn't be necessary because all versions of Mac Catalyst should
have a version of Combine available.
@sharplet
Copy link
Contributor Author

!os(Linux) didn't work, and I released that because Catalyst is brand new there should always be a version of Combine available. 🤞

@sharplet
Copy link
Contributor Author

Good news: CombineTests is actually running now on the Xcode 11 job, but it's crashing, which might be because the job is linking against the macOS SDK, but is running on 10.14 where Combine.framework isn't available at runtime. That test run might need to use the iOS SDK in order to successfully link against Combine.

README.md Show resolved Hide resolved
var name: String
}

@available(iOS 13.0, macOS 10.15.0, tvOS 13.0, watchOS 6.0, *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the solution would be to remove macOS 10.15.0 clause until that's released? We would avoid crashing on CI until then too. After all I wouldn't mind tagging a minor release just for enabling that later when Catalina is released and available on CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing macOS from the availability annotation would instead result in a compiler error. The issue is that we successfully compile & link, but then attempt to run the tests on a platform where the framework doesn't exist and instead crash when the symbol can't be loaded.

If we want to exclude the test from macOS altogether, we could add #if !os(macOS) to the compiler directive at the top of the file. The tests won't be exercised on CI then, so it might still make sense to add a CI job that runs on Xcode 11 + iOS?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Xcode 11 job already tests on macOS, iOS and tvOS, so that should be fine.

Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the PR!

@MaxDesiatov MaxDesiatov merged commit c4b78cb into CoreOffice:master Oct 4, 2019
bwetherfield pushed a commit to bwetherfield/XMLCoder that referenced this pull request Oct 16, 2019
This enables use of `XMLDecoder` with Combine's `decode(_:decoder:)` operator by conditionally conforming to `TopLevelDecoder` when Combine is available.

I explored doing the same for `TopLevelEncoder`, but `XMLEncoder` currently requires `rootKey:` to be specified at encoding time, so it's not possible to provide an implementation of `encode(_:)` without some design around how to dynamically determine the root key to use.

* Conditionally conform to Combine.TopLevelDecoder
* Add test and documentation for Combine integration
* Remove macCatalyst from CombineTests
This shouldn't be necessary because all versions of Mac Catalyst should
have a version of Combine available.
* Add CombineTests to the Xcode project
* Disable CombineTests on macOS
arjungupta0107 pushed a commit to salido/XMLCoder that referenced this pull request Jun 26, 2020
This enables use of `XMLDecoder` with Combine's `decode(_:decoder:)` operator by conditionally conforming to `TopLevelDecoder` when Combine is available.

I explored doing the same for `TopLevelEncoder`, but `XMLEncoder` currently requires `rootKey:` to be specified at encoding time, so it's not possible to provide an implementation of `encode(_:)` without some design around how to dynamically determine the root key to use.

* Conditionally conform to Combine.TopLevelDecoder
* Add test and documentation for Combine integration
* Remove macCatalyst from CombineTests
This shouldn't be necessary because all versions of Mac Catalyst should
have a version of Combine available.
* Add CombineTests to the Xcode project
* Disable CombineTests on macOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants