Skip to content

Commit 7f75344

Browse files
authored
AnyHashable (#8)
* Output as AnyHashable Also: Expose geometry.toJSON
1 parent 077d3ca commit 7f75344

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Sources/GeoJSONKit/GeoJSON.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public struct GeoJSON: Hashable {
110110
}
111111
}
112112

113-
fileprivate func toJSON(prune: Bool) -> [String: Any] {
113+
public func toJSON(prune: Bool) -> [String: AnyHashable] {
114114
var json: [String: Any] = [
115115
"type": type.rawValue
116116
]
@@ -124,7 +124,7 @@ public struct GeoJSON: Hashable {
124124
json["geometries"] = geometries.map { $0.toJSON(prune: prune) }
125125
}
126126

127-
return json
127+
return json.hashable
128128
}
129129

130130
}
@@ -307,14 +307,14 @@ public struct GeoJSON: Hashable {
307307
id = dict["id"] as? AnyHashable
308308
}
309309

310-
public func toJSON(prune: Bool = true) -> [String: Any] {
310+
public func toJSON(prune: Bool = true) -> [String: AnyHashable] {
311311
var json: [String: Any] = [
312312
"type": "Feature",
313313
"geometry": geometry.toJSON(prune: prune)
314314
]
315315
json["properties"] = prune ? properties?.prune : properties
316316
json["id"] = id
317-
return json
317+
return json.hashable
318318
}
319319
}
320320

@@ -494,7 +494,7 @@ public struct GeoJSON: Hashable {
494494
return try JSONSerialization.data(withJSONObject: toJSON(prune: prune), options: options)
495495
}
496496

497-
public func toJSON(prune: Bool = true) -> [String: Any] {
497+
public func toJSON(prune: Bool = true) -> [String: AnyHashable] {
498498
var json = [String: Any]()
499499

500500
json["type"] = type.rawValue
@@ -516,7 +516,7 @@ public struct GeoJSON: Hashable {
516516
let additional = prune ? additionalFields.prune : additionalFields
517517
json.merge(additional) { a, _ in a }
518518

519-
return json
519+
return json.hashable
520520
}
521521

522522
}
@@ -568,4 +568,8 @@ fileprivate extension Dictionary {
568568
var prune: [Key: Any] {
569569
mapValues(Adjuster.prune(_:))
570570
}
571+
572+
var hashable: [Key: AnyHashable] {
573+
compactMapValues(Adjuster.hashable(_:))
574+
}
571575
}

0 commit comments

Comments
 (0)