CoreOffice / XMLCoder

Easy XML parsing using Codable protocols in Swift
https://coreoffice.github.io/XMLCoder/
MIT License
801 stars 112 forks source link

Conditionally conform to Combine.TopLevelDecoder #132

Closed sharplet closed 5 years ago

sharplet commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

sharplet commented 5 years ago

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 commented 5 years ago

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.

sharplet commented 5 years ago

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

sharplet commented 5 years ago

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.