diff --git a/Sources/GISTools/GeoJson/Feature.swift b/Sources/GISTools/GeoJson/Feature.swift index 2006a45..0411435 100644 --- a/Sources/GISTools/GeoJson/Feature.swift +++ b/Sources/GISTools/GeoJson/Feature.swift @@ -1,7 +1,10 @@ import Foundation /// A GeoJSON `Feature`. -public struct Feature: GeoJson, Identifiable { +public struct Feature: + GeoJson, + Identifiable +{ /// A GeoJSON identifier that can either be a string or number. /// @@ -104,7 +107,7 @@ public struct Feature: GeoJson, Identifiable { public init( _ geometry: GeoJsonGeometry, id: Identifier? = nil, - properties: [String: Any] = [:], + properties: [String: Sendable] = [:], calculateBoundingBox: Bool = false) { self.geometry = geometry @@ -121,14 +124,14 @@ public struct Feature: GeoJson, Identifiable { } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], Feature.isValid(geoJson: geoJson), let geometry: GeoJsonGeometry = Feature.tryCreateGeometry(json: geoJson["geometry"]) else { return nil } self.geometry = geometry self.id = Identifier(value: geoJson["id"]) - self.properties = (geoJson["properties"] as? [String: Any]) ?? [:] + self.properties = (geoJson["properties"] as? [String: Sendable]) ?? [:] self.boundingBox = Feature.tryCreate(json: geoJson["bbox"]) if calculateBoundingBox, self.boundingBox == nil { @@ -223,14 +226,14 @@ extension Feature { extension Feature { /// Returns a property by key. - public func property(for key: String) -> T? { + public func property(for key: String) -> T? { return properties[key] as? T } /// Set a property key/value pair. /// /// - important: `value` must be a valid JSON object or serialization will fail. - public mutating func setProperty(_ value: Any?, for key: String) { + public mutating func setProperty(_ value: Sendable?, for key: String) { var updatedProperties = properties updatedProperties[key] = value properties = updatedProperties @@ -238,7 +241,7 @@ extension Feature { /// Remove a property from the Feature. @discardableResult - public mutating func removeProperty(for key: String) -> Any? { + public mutating func removeProperty(for key: String) -> Sendable? { var updatedProperties = properties let previous = updatedProperties.removeValue(forKey: key) properties = updatedProperties @@ -246,7 +249,7 @@ extension Feature { } /// Returns a property by key. - public subscript(key: String) -> T? { + public subscript(key: String) -> T? { get { return property(for: key) } diff --git a/Sources/GISTools/GeoJson/FeatureCollection.swift b/Sources/GISTools/GeoJson/FeatureCollection.swift index c379320..898d3e1 100644 --- a/Sources/GISTools/GeoJson/FeatureCollection.swift +++ b/Sources/GISTools/GeoJson/FeatureCollection.swift @@ -94,7 +94,7 @@ public struct FeatureCollection: } // To prevent an infinite recursion. - init?(geoJson: [String: Any], calculateBoundingBox: Bool = false) { + init?(geoJson: [String: Sendable], calculateBoundingBox: Bool = false) { guard FeatureCollection.isValid(geoJson: geoJson), let features: [Feature] = FeatureCollection.tryCreate(json: geoJson["features"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/GeoJson.swift b/Sources/GISTools/GeoJson/GeoJson.swift index 52c58c5..ecb441a 100644 --- a/Sources/GISTools/GeoJson/GeoJson.swift +++ b/Sources/GISTools/GeoJson/GeoJson.swift @@ -91,14 +91,14 @@ extension GeoJson { extension GeoJson { /// Any foreign member by key. - public func foreignMember(for key: String) -> T? { + public func foreignMember(for key: String) -> T? { return foreignMembers[key] as? T } /// Set a foreign member key/value pair. /// /// - important: `value` must be a valid JSON object or serialization will fail. - public mutating func setForeignMember(_ value: Any?, for key: String) { + public mutating func setForeignMember(_ value: Sendable?, for key: String) { var updatedProperties = foreignMembers updatedProperties[key] = value foreignMembers = updatedProperties @@ -106,7 +106,7 @@ extension GeoJson { /// Remove a foreign member from the receiver. @discardableResult - public mutating func removeForeignMember(for key: String) -> Any? { + public mutating func removeForeignMember(for key: String) -> Sendable? { var updatedProperties = foreignMembers let previous = updatedProperties.removeValue(forKey: key) foreignMembers = updatedProperties @@ -114,7 +114,7 @@ extension GeoJson { } /// Any foreign member by subscript. - public subscript(foreignMember key: String) -> T? { + public subscript(foreignMember key: String) -> T? { get { return foreignMember(for: key) } @@ -228,7 +228,7 @@ extension GeoJson { /// Try to create a GeoJSON object from any JSON object. public static func tryCreate(json: Any?) -> GeoJson? { - if let geoJson = json as? [String: Any], + if let geoJson = json as? [String: Sendable], let typeString = geoJson["type"] as? String, let type = GeoJsonType(rawValue: typeString), type != .invalid @@ -251,7 +251,7 @@ extension GeoJson { /// Try to create a GeoJSON geometry from any JSON object. public static func tryCreateGeometry(json: Any?) -> GeoJsonGeometry? { - if let geoJson = json as? [String: Any], + if let geoJson = json as? [String: Sendable], let typeString = geoJson["type"] as? String, let type = GeoJsonType(rawValue: typeString), type != .invalid diff --git a/Sources/GISTools/GeoJson/GeometryCollection.swift b/Sources/GISTools/GeoJson/GeometryCollection.swift index ae27909..d5f3556 100644 --- a/Sources/GISTools/GeoJson/GeometryCollection.swift +++ b/Sources/GISTools/GeoJson/GeometryCollection.swift @@ -41,7 +41,7 @@ public struct GeometryCollection: GeoJsonGeometry { } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], GeometryCollection.isValid(geoJson: geoJson), let geometries: [GeoJsonGeometry] = GeometryCollection.tryCreate(json: geoJson["geometries"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/LineString.swift b/Sources/GISTools/GeoJson/LineString.swift index 8974cab..7704b45 100644 --- a/Sources/GISTools/GeoJson/LineString.swift +++ b/Sources/GISTools/GeoJson/LineString.swift @@ -94,7 +94,7 @@ public struct LineString: } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], LineString.isValid(geoJson: geoJson), let coordinates: [Coordinate3D] = LineString.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/MultiLineString.swift b/Sources/GISTools/GeoJson/MultiLineString.swift index e9f7855..527e743 100644 --- a/Sources/GISTools/GeoJson/MultiLineString.swift +++ b/Sources/GISTools/GeoJson/MultiLineString.swift @@ -91,7 +91,7 @@ public struct MultiLineString: } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], MultiLineString.isValid(geoJson: geoJson), let coordinates: [[Coordinate3D]] = MultiLineString.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/MultiPoint.swift b/Sources/GISTools/GeoJson/MultiPoint.swift index 102f2f2..78a1aaa 100644 --- a/Sources/GISTools/GeoJson/MultiPoint.swift +++ b/Sources/GISTools/GeoJson/MultiPoint.swift @@ -73,7 +73,7 @@ public struct MultiPoint: } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], MultiPoint.isValid(geoJson: geoJson), let coordinates: [Coordinate3D] = MultiPoint.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/MultiPolygon.swift b/Sources/GISTools/GeoJson/MultiPolygon.swift index 80baa26..6d63d68 100644 --- a/Sources/GISTools/GeoJson/MultiPolygon.swift +++ b/Sources/GISTools/GeoJson/MultiPolygon.swift @@ -76,7 +76,7 @@ public struct MultiPolygon: } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], MultiPolygon.isValid(geoJson: geoJson), let coordinates: [[[Coordinate3D]]] = MultiPolygon.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/Point.swift b/Sources/GISTools/GeoJson/Point.swift index fb21fff..7b17d30 100644 --- a/Sources/GISTools/GeoJson/Point.swift +++ b/Sources/GISTools/GeoJson/Point.swift @@ -43,7 +43,7 @@ public struct Point: PointGeometry { } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], Point.isValid(geoJson: geoJson), let coordinate: Coordinate3D = Point.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/Polygon.swift b/Sources/GISTools/GeoJson/Polygon.swift index 75e644d..5032cc0 100644 --- a/Sources/GISTools/GeoJson/Polygon.swift +++ b/Sources/GISTools/GeoJson/Polygon.swift @@ -92,7 +92,7 @@ public struct Polygon: } public init?(json: Any?, calculateBoundingBox: Bool = false) { - guard let geoJson = json as? [String: Any], + guard let geoJson = json as? [String: Sendable], Polygon.isValid(geoJson: geoJson), let coordinates: [[Coordinate3D]] = Polygon.tryCreate(json: geoJson["coordinates"]) else { return nil } diff --git a/Sources/GISTools/GeoJson/WKBCoder.swift b/Sources/GISTools/GeoJson/WKBCoder.swift index 1247d8e..55d5a5e 100644 --- a/Sources/GISTools/GeoJson/WKBCoder.swift +++ b/Sources/GISTools/GeoJson/WKBCoder.swift @@ -73,7 +73,7 @@ extension Feature { sourceSrid: Int?, targetProjection: Projection = .epsg4326, id: Identifier? = nil, - properties: [String: Any] = [:], + properties: [String: Sendable] = [:], calculateBoundingBox: Bool = false) { guard let geometry = try? WKBCoder.decode(wkb: wkb, sourceSrid: sourceSrid, targetProjection: targetProjection) else { return nil } @@ -88,7 +88,7 @@ extension Feature { sourceProjection: Projection, targetProjection: Projection = .epsg4326, id: Identifier? = nil, - properties: [String: Any] = [:], + properties: [String: Sendable] = [:], calculateBoundingBox: Bool = false) { guard let geometry = try? WKBCoder.decode(wkb: wkb, sourceProjection: sourceProjection, targetProjection: targetProjection) else { return nil } @@ -172,7 +172,7 @@ extension Data { sourceSrid: Int?, targetProjection: Projection = .epsg4326, id: Feature.Identifier? = nil, - properties: [String: Any] = [:]) + properties: [String: Sendable] = [:]) -> Feature? { Feature(wkb: self, sourceSrid: sourceSrid, targetProjection: targetProjection, id: id, properties: properties) @@ -185,7 +185,7 @@ extension Data { sourceProjection: Projection, targetProjection: Projection = .epsg4326, id: Feature.Identifier? = nil, - properties: [String: Any] = [:]) + properties: [String: Sendable] = [:]) -> Feature? { Feature(wkb: self, sourceProjection: sourceProjection, targetProjection: targetProjection, id: id, properties: properties) diff --git a/Sources/GISTools/GeoJson/WKTCoder.swift b/Sources/GISTools/GeoJson/WKTCoder.swift index 947212a..0184973 100644 --- a/Sources/GISTools/GeoJson/WKTCoder.swift +++ b/Sources/GISTools/GeoJson/WKTCoder.swift @@ -73,7 +73,7 @@ extension Feature { sourceSrid: Int?, targetProjection: Projection = .epsg4326, id: Identifier? = nil, - properties: [String: Any] = [:], + properties: [String: Sendable] = [:], calculateBoundingBox: Bool = false) { guard let geometry = try? WKTCoder.decode(wkt: wkt, sourceSrid: sourceSrid, targetProjection: targetProjection) else { return nil } @@ -88,7 +88,7 @@ extension Feature { sourceProjection: Projection, targetProjection: Projection = .epsg4326, id: Identifier? = nil, - properties: [String: Any] = [:], + properties: [String: Sendable] = [:], calculateBoundingBox: Bool = false) { guard let geometry = try? WKTCoder.decode(wkt: wkt, sourceProjection: sourceProjection, targetProjection: targetProjection) else { return nil } @@ -182,7 +182,7 @@ extension String { sourceSrid: Int?, targetProjection: Projection = .epsg4326, id: Feature.Identifier? = nil, - properties: [String: Any] = [:]) + properties: [String: Sendable] = [:]) -> Feature? { Feature(wkt: self, sourceSrid: sourceSrid, targetProjection: targetProjection, id: id, properties: properties) @@ -195,7 +195,7 @@ extension String { sourceProjection: Projection, targetProjection: Projection = .epsg4326, id: Feature.Identifier? = nil, - properties: [String: Any] = [:]) + properties: [String: Sendable] = [:]) -> Feature? { Feature(wkt: self, sourceProjection: sourceProjection, targetProjection: targetProjection, id: id, properties: properties) diff --git a/Tests/GISToolsTests/Helpers/TestData.swift b/Tests/GISToolsTests/Helpers/TestData.swift index 342b4b7..60c74d6 100644 --- a/Tests/GISToolsTests/Helpers/TestData.swift +++ b/Tests/GISToolsTests/Helpers/TestData.swift @@ -43,7 +43,7 @@ class TestData { // MARK: - class func stringFromFile(package: String, name: String) -> String { - let path = URL(fileURLWithPath: #file) + let path = URL(fileURLWithPath: #filePath) .deletingLastPathComponent() .deletingLastPathComponent() .appendingPathComponent("TestData") @@ -65,13 +65,13 @@ class TestData { } class func dataFromFile(package: String, name: String) -> Data { - let path = URL(fileURLWithPath: #file) + let path = URL(fileURLWithPath: #filePath) .deletingLastPathComponent() .deletingLastPathComponent() .appendingPathComponent("TestData") .appendingPathComponent(package) .appendingPathComponent(name) - .appendingPathExtension("geojson") + .appendingPathExtension("geojson") do { if !(try path.checkResourceIsReachable()) {