mapbox / turf-swift

A Swift language port of Turf.js.
https://mapbox.github.io/turf-swift/
ISC License
235 stars 55 forks source link

JSONArray: RawRepresentable conflicts with Array: RawRepresentable where Element: Codable #217

Open hermiteer opened 5 months ago

hermiteer commented 5 months ago

There's a popular pattern of folks extending arrays of Codable to allow use with @AppStorage as described here:

https://stackoverflow.com/questions/62562534/swiftui-what-is-appstorage-property-wrapper/62563773#62563773

Unfortunately Turf's JSONArray conflicts with this extension due to:

Conflicting conformance of 'Array<Element>' to protocol 'RawRepresentable'; there cannot be more than one conformance, even with different conditional bounds

If Swift won't allow multiple RawRepresentable extensions, what are our options here? Is it possible to keep JSONArray internal to the Turf package? For that matter, do any of the JSON types need to be public?

So far I've been unable to find another way to express the Array extension that makes the compiler happy, so would love to hear any other ideas.

Note: I'm not using Turf directly, it comes with the Mapbox SDK.

1ec5 commented 3 weeks ago

The RawRepresentable usage in this package always seemed a bit too magical to me, but people seemed to like how it led to less typing when writing runtime styling code in the map SDK. #219 would replace this conformance with something more custom, also for JSONObject.