-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
178 additions
and
138 deletions.
There are no files selected for viewing
File renamed without changes.
17 changes: 0 additions & 17 deletions
17
app/metro-now/metro-now-tests/getStationsFromJSONTest.swift
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// jsonUtilsTests.swift | ||
// metro-now-tests | ||
// | ||
// Created by Kryštof Krátký on 15.05.2024. | ||
// | ||
|
||
@testable import metro_now | ||
import XCTest | ||
|
||
final class jsonUtilsTests: XCTestCase { | ||
// MARK: - check if JSON data loads successfully | ||
|
||
func testStationsJSON() { | ||
let result: [Station]? = getParsedJSONFile(.METRO_STATIONS_FILE) | ||
|
||
XCTAssertNotNil(result) | ||
} | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// fileUtils.swift | ||
// metro-now | ||
// | ||
// Created by Kryštof Krátký on 16.05.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
enum FileName: String { | ||
case METRO_STATIONS_FILE = "metro-stations" | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// jsonUtils.swift | ||
// metro-now | ||
// | ||
// Created by Kryštof Krátký on 15.05.2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Station: Codable { | ||
let name: String | ||
let avgLat, avgLon: Double | ||
let platforms: [Platform] | ||
} | ||
|
||
struct Platform: Codable { | ||
let gtfsID, name, direction: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case gtfsID | ||
case name, direction | ||
} | ||
} | ||
|
||
func getParsedJSONFile<T: Decodable>(_ filename: FileName) -> T? { | ||
let path = Bundle.main.path(forResource: filename.rawValue, ofType: "json") | ||
|
||
guard let path else { | ||
print("File not found") | ||
return nil | ||
} | ||
|
||
do { | ||
let data = try Data( | ||
contentsOf: URL(fileURLWithPath: path) | ||
) | ||
let stations = try JSONDecoder().decode( | ||
T.self, | ||
from: data | ||
) | ||
return stations | ||
} catch { | ||
print("Error parsing JSON: \(error)") | ||
return nil | ||
} | ||
} |
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
Oops, something went wrong.