Is there a way to create an array of items to populate a list view that all have navigation links? I am trying to make the below code work so that each item that populates the list view can then link to a another view that has descriptions of the item in the list. Thanks in advance for any and all help!
import SwiftUI
struct Restaurant: Identifiable {
var id = UUID()
var name: String
//var destination:
}
struct RestaurantRow: View {
var restaurant: Restaurant
var body: some View {
Text("Come and eat at \(restaurant.name)")
}
}
struct Parts: View {
var body: some View {
let restaurants = [Restaurant(name: "1"), Restaurant(name: "2"), Restaurant(name: "3"), Restaurant(name: "4"), Restaurant(name: "5"), Restaurant(name: "6"), Restaurant(name: "7"), Restaurant(name: "8"), Restaurant(name: "9"), Restaurant(name: "10"), Restaurant(name: "11"), Restaurant(name: "12"), Restaurant(name: "1"), Restaurant(name: "2"), Restaurant(name: "3"), Restaurant(name: "4"), Restaurant(name: "5"), Restaurant(name: "6"), Restaurant(name: "7"), Restaurant(name: "8"), Restaurant(name: "9"), Restaurant(name: "10"), Restaurant(name: "11"), Restaurant(name: "12")]
return List(restaurants) { restaurant in
RestaurantRow(restaurant: restaurant)
}
.listStyle(GroupedListStyle())
.environment(\.horizontalSizeClass, .regular)
}
}
struct Parts_Previews: PreviewProvider {
static var previews: some View {
Parts()
}
}
Is this what you're looking for?