40 lines
1015 B
Swift
40 lines
1015 B
Swift
//
|
|
// CourseCatalogView.swift
|
|
// CourseCatalogView
|
|
//
|
|
// Created by Felix Förtsch on 01.08.21.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct CourseCatalogView: View {
|
|
func parse() -> [Course] {
|
|
let url = Bundle.main.url(forResource: "courses", withExtension: "json")!
|
|
let data = try! Data(contentsOf: url)
|
|
let decoder = JSONDecoder()
|
|
let products = try? decoder.decode([Course].self, from: data)
|
|
return products!
|
|
}
|
|
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
List{
|
|
ForEach(parse(), id: \.self) { item in
|
|
VStack(alignment: .leading, spacing: 0){
|
|
Text("name:\(item.name)")
|
|
Text("\(item.description)")
|
|
}
|
|
}
|
|
}
|
|
.navigationBarTitle("Courses")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CourseCatalogView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CourseCatalogView().preferredColorScheme(.dark)
|
|
}
|
|
}
|