diff --git a/DataView.swift b/DataView.swift index 1b72825..27e370f 100644 --- a/DataView.swift +++ b/DataView.swift @@ -14,13 +14,14 @@ struct MenuCard: Codable { struct MenuItem: Codable { let name: String - let detailText: String + let description: String + let imageUrl: URL // let price: Double - enum CodingKeys: String, CodingKey { - case name - case detailText = "description" - } + // enum CodingKeys: String, CodingKey { + // case name + // case detailText = "description" + // } } struct DataView: View { @@ -28,7 +29,7 @@ struct DataView: View { private let url = URL(string: "http://127.0.0.1:8080/menu")! private let jsonDecoder = JSONDecoder() @State private var menu = MenuCard(items: []) - + var body: some View { Text(url.absoluteString) .onAppear{ @@ -42,15 +43,25 @@ struct DataView: View { ) else { return } if let response = response as? HTTPURLResponse, response.statusCode == 200 { - menu = try! JSONDecoder().decode(MenuCard.self, from: data) - + jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase + + menu = try! jsonDecoder.decode(MenuCard.self, from: data) + + } print("fertig geladen") print(string) } } - Text("asdlfaksdf") + + ForEach(menu.items, id: \.name) { item in + HStack { + AsyncImage(url: item.imageUrl, scale: 12) + // Text(item.imageUrl.absoluteString ) + Text(item.description ) + } + } } } diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 645edcf..d760fbc 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -20,10 +20,6 @@ "comment" : "The title of a section that displays information about the API.", "isCommentAutoGenerated" : true }, - "asdlfaksdf" : { - "comment" : "A placeholder text.", - "isCommentAutoGenerated" : true - }, "Betrag" : { "comment" : "A text field for entering an amount.", "isCommentAutoGenerated" : true diff --git a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate index 27403da..8e40571 100644 Binary files a/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate and b/TheSwiftWeek.xcodeproj/project.xcworkspace/xcuserdata/rohing73.xcuserdatad/UserInterfaceState.xcuserstate differ