I\'m trying to work through understanding how I can make data flow nicely through an app I\'m building. I just want a basic master detail view where it starts with a list of all
Your CityModel and TownModel need to conform to Identifiable, just add an id to them like you did in UserModel.
Than you need to edit your UserList NavigationLink:
NavigationLink(destination: CityList(cities: user.cities)) {
Text(user.firstName)
}
The Navigation is now like this: UserList -> CityList -> TownList
CityList:
struct CityList: View {
var cities: [CityModel]
var body: some View {
List (cities) { city in
NavigationLink(destination: TownList(towns: city.towns)) {
Text(city.name)
}
}
}
}
TownList:
struct TownList: View {
var towns: [TownModel]
var body: some View {
List (towns) { town in
Text(town.name)
}
}
}
I hope that helps, in my test project it works!