-
-
Save JeffLutzenberger/369d3062dafb5925d9641119eef41edd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A GeoJSON identifier that can either be a string or number. | |
public enum Identifier: Equatable, Hashable, CustomStringConvertible, Sendable { | |
case string(String) | |
case int(Int64) | |
case double(Double) | |
public init?(value: Any?) { | |
guard let value else { return nil } | |
if let int = value as? Int64 { | |
self = .int(int) | |
} | |
else if let string = value as? String { | |
self = .string(string) | |
} | |
else if let double = value as? Double { | |
self = .double(double) | |
} | |
else { | |
return nil | |
} | |
} | |
public var asJson: Any { | |
switch self { | |
case .double(let double): return double | |
case .int(let int): return int | |
case .string(let string): return string | |
} | |
} | |
public var description: String { | |
switch self { | |
case .double(let double): return String(double) | |
case .int(let int): return String(int) | |
case .string(let string): return string | |
} | |
} | |
} | |
func testLoadJsonWithInt64Id() throws { | |
let bigInt64: Int64 = 0xFFFFFFFFFFFFFFF | |
let featureJsonWithInt64Id = """ | |
{ | |
"type": "Feature", | |
"geometry": { | |
"type": "Polygon", | |
"coordinates": [ | |
[ | |
[100.0, 0.0], | |
[101.0, 0.0], | |
[101.0, 1.0], | |
[100.0, 1.0], | |
[100.0, 0.0] | |
] | |
] | |
}, | |
"properties": { | |
"prop0": "value0", | |
"prop1": { | |
"this": "that" | |
} | |
}, | |
"other": "something else", | |
"id": \(bigInt64) | |
} | |
""" | |
let feature = try XCTUnwrap(Feature(jsonString: featureJsonWithInt64Id)) | |
XCTAssertEqual(feature.id, .int(bigInt64)) | |
XCTAssertEqual(feature.projection, .epsg4326) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment