|
struct FoodGroup { |
|
var name: String |
|
var examples: [String] |
|
} |
|
|
|
struct ContentView: View { |
|
var foodGroups: [FoodGroup] { |
|
let fruits = FoodGroup(name: "Fruit", examples: ["Apple", "Banana", "Pear", "Peach", "Mango", "Orange", "Strawberry", "Watermelon", "Pineapple", "Lemon", "Lime", "Cherry", "Date", "Plum", "Apricot", "Blueberry", "Blackberry", "Cranberry", "Kiwi", "Nectarine"]) |
|
let vegetables = FoodGroup(name: "Vegetables", examples: ["Lettuce", "Carrot", "Beet", "Broccoli", "Corn", "Celery", "Chicory", "Kale", "Spinach", "Yarrow", "Brussels sprouts", "Arugula", "Cauliflower", "Turnip", "Sweet Potato"]) |
|
return [fruits, vegetables] |
|
} |
|
|
|
@State var isDetailLink = true |
|
var body: some View { |
|
NavigationView { |
|
List { |
|
ForEach(foodGroups, id: \.name) { foodGroup in |
|
NavigationLink( |
|
destination: DetailView(foodGroup: foodGroup), |
|
label: { |
|
Text(foodGroup.name) |
|
}) |
|
.isDetailLink(isDetailLink) |
|
} |
|
Button(action: {isDetailLink.toggle()}, label: { |
|
Text("Detail link: \(String(isDetailLink))") |
|
}) |
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
} |
|
.navigationTitle(Text("Food Groups")) |
|
} |
|
} |
|
} |