-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bruno Muniz Azevedo Filho
committed
Oct 3, 2023
1 parent
7d4a0f7
commit 8788955
Showing
11 changed files
with
73,390 additions
and
108 deletions.
There are no files selected for viewing
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,16 @@ | ||
struct Airport: Codable, Identifiable { | ||
let id: String | ||
let lon: String? | ||
let iso: String | ||
let status: Int | ||
let name: String | ||
let continent: String | ||
let type: String | ||
let lat: String? | ||
let size: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id = "iata" | ||
case lon, iso, status, name, continent, type, lat, size | ||
} | ||
} |
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,32 @@ | ||
import SwiftUI | ||
|
||
struct AirportListView: View { | ||
@StateObject var viewModel = AirportListViewModel() | ||
|
||
var body: some View { | ||
NavigationView { | ||
List(viewModel.airports) { airport in | ||
NavigationLink { | ||
Text(airport.id) | ||
Text(airport.name) | ||
Text(airport.continent) | ||
if let lat = airport.lat { | ||
Text(lat) | ||
} | ||
if let lon = airport.lon { | ||
Text(lon) | ||
} | ||
} label: { | ||
Text(airport.name) | ||
} | ||
} | ||
.navigationTitle("Airports") | ||
} | ||
} | ||
} | ||
|
||
struct AirportListView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
AirportListView() | ||
} | ||
} |
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,24 @@ | ||
import Foundation | ||
|
||
class AirportListViewModel: ObservableObject { | ||
@Published var airports: [Airport] = [] | ||
|
||
init() { | ||
loadAirports() | ||
} | ||
|
||
private func loadAirports() { | ||
guard let url = Bundle.main.url(forResource: "airports", withExtension: "json") else { | ||
print("Invalid filename/path.") | ||
return | ||
} | ||
|
||
do { | ||
let data = try Data(contentsOf: url) | ||
let decoder = JSONDecoder() | ||
self.airports = try decoder.decode([Airport].self, from: data) | ||
} catch { | ||
print("Error decoding the airport list: \(error)") | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,10 @@ | ||
// | ||
// AirportsApp.swift | ||
// Airports | ||
// | ||
// Created by Bruno Muniz on 10/2/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct AirportsApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,24 +1,13 @@ | ||
// | ||
// ContentView.swift | ||
// Airports | ||
// | ||
// Created by Bruno Muniz on 10/2/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
VStack { | ||
Image(systemName: "globe") | ||
.imageScale(.large) | ||
.foregroundStyle(.tint) | ||
Text("Hello, world!") | ||
} | ||
.padding() | ||
} | ||
var body: some View { | ||
AirportListView() | ||
} | ||
} | ||
|
||
#Preview { | ||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
Oops, something went wrong.