struct TodaysMenuOptionsView: View {
@Binding var menuItems: OrderedDictionary
var body: some View {
ZStack(alignment: .leading) {
ForEach(menuItems.keys.sorted(), id: \.self) { key in
RoundedRectangle(cornerRadius: 10)
.fill(Color("Menu Options Color"))
.frame(height: 100)
VStack(alignment: .leading) {
Text(key)
.font(.title3)
.fontWeight(.semibold)
if let value = menuItems[key] {
HStack {
ForEach(value, id: \.self) { item in
Text(item)
}
}
}
}
.padding()
}
.padding()
}
}
}
Вот фрагмент JSON, с которым я работаю:
{
"day": "Friday",
"locationName": "Memorial Union Quad",
"coordinate": [38.54141, -121.74845],
"menu": [
"Soy Ciltrano Lime Chicken",
["
"Southwest Tofu",
["🫛","V"]
]
}
Вот как моделирование данных выглядит в Swift:
import Foundation
import OrderedCollections
struct Menu : Codable, Hashable {
var id: UUID { UUID() }
let day: String
let locationName: String
let coordinate: [Double]
let menu: OrderedDictionary
func getTodaysLocation(_ today: String)-> String{
if today == day{
return locationName
}
return ""
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... rom-a-json
Мобильная версия