We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f200570 commit a40e0fcCopy full SHA for a40e0fc
2 files changed
Sources/GeoJSONKit/GeoJSON.swift
@@ -419,6 +419,12 @@ public struct GeoJSON: Hashable {
419
guard let dict = decoded as? [String: Any] else {
420
throw SerializationError.unexpectedRoot
421
}
422
+
423
+ try self.init(from: dict)
424
+ }
425
426
+ public init(from dict: [String: Any]) throws {
427
428
guard let typeString = dict["type"] as? String, let type = GeoJSONType(rawValue: typeString) else {
429
throw SerializationError.missingOrInvalidRequiredField("type")
430
Tests/GeoJSONKitTests/GeoJSONParserTest.swift
@@ -213,6 +213,14 @@ final class GeoJSONParserTest: XCTestCase {
213
XCTAssertNotNil(parsed)
214
215
216
+ func testFeatureCollectionFromDict() throws {
217
+ let data = try XCTestCase.loadData(filename: "featurecollection")
218
+ let object = try JSONSerialization.jsonObject(with: data, options: [])
219
+ let dict = try XCTUnwrap(object as? [String: Any])
220
+ let parsed = try GeoJSON(from: dict)
221
+ XCTAssertNotNil(parsed)
222
223
224
static var allTests = [
225
("testPoint", testPoint),
226
("testMultiPoint", testMultiPoint),
@@ -223,6 +231,7 @@ final class GeoJSONParserTest: XCTestCase {
231
("testMultiPolygon", testMultiPolygon),
232
("testFeatureCollection", testFeatureCollection),
233
("testGeometryCollection", testGeometryCollection),
234
+ ("testFeatureCollectionFromDict", testFeatureCollectionFromDict),
235
("testTripGo", testTripGo),
227
236
("testWorld", testWorld),
228
237
("testNuremberg", testNuremberg),
0 commit comments