Geometric types should conform to common protocol that converts to Geometry
1ec5 opened this issue · 3 comments
GEOSwift defines a GeometryConvertible protocol that makes it possible to initialize a Feature without redundantly specifying both the Geometry case and the geometric type’s initializer at the same time. Turf’s GeoJSONObject and Geometry enumerations should have something similar. For example:
var geoJSON = Feature(geometry: .point(Point(coordinate)))
would become simply:
var geoJSON = Feature(geometry: Point(coordinate))
It’s similar to the initializers and literals that #154 added to JSONValue, but this protocol distributes the implementation across each type:
turf-swift/Sources/Turf/JSON.swift
Lines 49 to 52 in 007896b
/cc @macdrevx
A similar JSONValueConvertible protocol might eliminate a major backwards-incompatible change that arose in #154, making both syntaxes equivalent again:
feature.properties = [
"literal": "Jason",
"non-literal": .string(name),
]
feature.properties = [
"literal": "Jason",
"non-literal": name,
]
A similar JSONValueConvertible protocol might eliminate a major backwards-incompatible change that arose in #154, making both syntaxes equivalent again
I’ve been trying various gymnastics but haven’t managed to make this work without making [String: Any?]
conform to ExpressibleByArrayLiteral
, which would be overbroad.