From 781dee730b4e2a92ff012374acdc234281e5f89d Mon Sep 17 00:00:00 2001 From: Krystof Date: Tue, 21 May 2024 02:07:31 +0200 Subject: [PATCH] fix(app): json decode --- app/Common/Types/metroRoutesTypes.swift | 3 ++- app/Common/Utils/jsonUtils.swift | 4 +++- app/metro-now.xcodeproj/project.pbxproj | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Common/Types/metroRoutesTypes.swift b/app/Common/Types/metroRoutesTypes.swift index 630f0be7..deba58c2 100644 --- a/app/Common/Types/metroRoutesTypes.swift +++ b/app/Common/Types/metroRoutesTypes.swift @@ -24,7 +24,8 @@ struct MetroRoutesGeoJSONFeatureGeometry: Codable { struct MetroRoutesGeoJSONFeatureGeometryProperties: Codable { let objectid: Int? - let routeID, routeShortName, routeLongName, routeType: String? + let routeShortName: String + let routeID, routeLongName, routeType: String? let routeURL: String? let routeColor, isNight, isRegional, isSubstituteTransport: String? let validity: String? diff --git a/app/Common/Utils/jsonUtils.swift b/app/Common/Utils/jsonUtils.swift index dd559372..de7aa981 100644 --- a/app/Common/Utils/jsonUtils.swift +++ b/app/Common/Utils/jsonUtils.swift @@ -18,7 +18,9 @@ func getParsedJSONFile(_ filename: FileName) -> T? { let data = try Data( contentsOf: URL(fileURLWithPath: path) ) - let stations = try JSONDecoder().decode( + let jsonDecoder = JSONDecoder() + jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase + let stations = try jsonDecoder.decode( T.self, from: data ) diff --git a/app/metro-now.xcodeproj/project.pbxproj b/app/metro-now.xcodeproj/project.pbxproj index af5ec741..f2c68cc0 100644 --- a/app/metro-now.xcodeproj/project.pbxproj +++ b/app/metro-now.xcodeproj/project.pbxproj @@ -23,11 +23,11 @@ 2D1B2C502BFAD8ED007ED5EB /* metroRoutesTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1B2C4E2BFAD8ED007ED5EB /* metroRoutesTypes.swift */; }; 2D1B2C522BFAD90B007ED5EB /* metroStationsTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1B2C512BFAD90B007ED5EB /* metroStationsTypes.swift */; }; 2D1B2C532BFAD90B007ED5EB /* metroStationsTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D1B2C512BFAD90B007ED5EB /* metroStationsTypes.swift */; }; - 2D1B2C572BFAD9FB007ED5EB /* metro-routes.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D1B2C552BFAD9FB007ED5EB /* metro-routes.geojson */; }; - 2D1B2C582BFAD9FB007ED5EB /* metro-routes.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D1B2C552BFAD9FB007ED5EB /* metro-routes.geojson */; }; 2D1B2C592BFAD9FB007ED5EB /* metro-stations.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D1B2C562BFAD9FB007ED5EB /* metro-stations.geojson */; }; 2D1B2C5A2BFAD9FB007ED5EB /* metro-stations.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D1B2C562BFAD9FB007ED5EB /* metro-stations.geojson */; }; 2D350E672BFBE50600F68039 /* MapStationAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D350E662BFBE50600F68039 /* MapStationAnnotationView.swift */; }; + 2D350E692BFBF6B100F68039 /* metro-routes.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D350E682BFBF6B100F68039 /* metro-routes.geojson */; }; + 2D350E6A2BFBF6B100F68039 /* metro-routes.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 2D350E682BFBF6B100F68039 /* metro-routes.geojson */; }; 2D4486862BFAA10A005C59CE /* metro_now_watchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4486852BFAA10A005C59CE /* metro_now_watchApp.swift */; }; 2D4486882BFAA10A005C59CE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4486872BFAA10A005C59CE /* ContentView.swift */; }; 2D44868A2BFAA10B005C59CE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2D4486892BFAA10B005C59CE /* Assets.xcassets */; }; @@ -89,9 +89,9 @@ 2D1B2C4A2BFAD807007ED5EB /* fileUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = fileUtils.swift; sourceTree = ""; }; 2D1B2C4E2BFAD8ED007ED5EB /* metroRoutesTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = metroRoutesTypes.swift; sourceTree = ""; }; 2D1B2C512BFAD90B007ED5EB /* metroStationsTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = metroStationsTypes.swift; sourceTree = ""; }; - 2D1B2C552BFAD9FB007ED5EB /* metro-routes.geojson */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "metro-routes.geojson"; path = "../../../data/metro-routes.geojson"; sourceTree = ""; }; 2D1B2C562BFAD9FB007ED5EB /* metro-stations.geojson */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "metro-stations.geojson"; path = "../../../data/metro-stations.geojson"; sourceTree = ""; }; 2D350E662BFBE50600F68039 /* MapStationAnnotationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapStationAnnotationView.swift; sourceTree = ""; }; + 2D350E682BFBF6B100F68039 /* metro-routes.geojson */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "metro-routes.geojson"; path = "../../../data/metro-routes.geojson"; sourceTree = ""; }; 2D4486832BFAA10A005C59CE /* metro-now-watch Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "metro-now-watch Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 2D4486852BFAA10A005C59CE /* metro_now_watchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = metro_now_watchApp.swift; sourceTree = ""; }; 2D4486872BFAA10A005C59CE /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -184,8 +184,8 @@ 2D1B2C542BFAD93F007ED5EB /* Data */ = { isa = PBXGroup; children = ( - 2D1B2C552BFAD9FB007ED5EB /* metro-routes.geojson */, 2D1B2C562BFAD9FB007ED5EB /* metro-stations.geojson */, + 2D350E682BFBF6B100F68039 /* metro-routes.geojson */, ); path = Data; sourceTree = ""; @@ -418,8 +418,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2D1B2C582BFAD9FB007ED5EB /* metro-routes.geojson in Resources */, 2D44868D2BFAA10B005C59CE /* Preview Assets.xcassets in Resources */, + 2D350E6A2BFBF6B100F68039 /* metro-routes.geojson in Resources */, 2D1B2C5A2BFAD9FB007ED5EB /* metro-stations.geojson in Resources */, 2D44868A2BFAA10B005C59CE /* Assets.xcassets in Resources */, ); @@ -429,8 +429,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2D1B2C572BFAD9FB007ED5EB /* metro-routes.geojson in Resources */, 2DC639E32BF3CCBC00A72C7F /* Preview Assets.xcassets in Resources */, + 2D350E692BFBF6B100F68039 /* metro-routes.geojson in Resources */, 2D1B2C592BFAD9FB007ED5EB /* metro-stations.geojson in Resources */, 2DC639E02BF3CCBC00A72C7F /* Assets.xcassets in Resources */, );