Since tuples aren’t Hashable
, you can’t use \.self
as the id
for your List
. You can, however, use one of the elements in the tuple as the id
, provided it is unique in the array you are looping through.
I’m still not 100% clear on what you are expecting to see in this particular View
, but here is a very simple example that should illustrate a way forward for you:
struct ZipperedList: View {
let days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
//I don't have your RestaurantItem data to use, so let's just use Strings
let entrees = ["Fish", "Shrimp", "Tacos", "Pizza", "Thai", "Burgers", "Steak", "Quinoa", "Chili", "Breakfast"]
@State private var meals: [(String, String)] = []
var body: some View {
VStack {
Text("Pull down to refresh list").font(.caption)
List(meals, id: \.0) { (day, entree) in
//\.0 refers to the first element in the tuple, i.e., the day
VStack(alignment: .leading) {
Text(day).bold().font(.title)
Text(entree).font(.title3)
}
}
.refreshable {
shuffleMeals()
}
}
.onAppear {
shuffleMeals()
}
}
func shuffleMeals() {
meals = Array(zip(days, entrees.shuffled()))
}
}