As I complete the 90 day lesson I am building an app much like the Recipe App. I have a list of JSON data. I only want to display certain data if the ‘checklists’ == true. It seems to only be pulling the boolean from the last data set in the JSON file. If it is true it lists all the data in the list (even if that datas ‘checklists’ was false. If the last data set was false it lists none. Newbie here…appreciate all the help. I suspect it has something to do with the ,ForEach’.
struct ChecklistView: View {
//reference the view model
@ObservedObject var model = TitleModel()
var body: some View {
NavigationView {
//loop through each title
ForEach (0..<model.titles.count) { index in
List(model.titles) { r in
//only show those that are true
if model.titles[index].checklists == true {
NavigationLink(
destination: DetailView(detail:r),
label: {
HStack(spacing: 20.0) {
Image(r.image1)
.resizable()
.scaledToFill()
.frame (width: 50, height: 50, alignment: .center)
.clipped()
.cornerRadius(5)
Text(r.title)
}
})
}
}
}
}
}
}
struct ChecklistView_Previews: PreviewProvider {
static var previews: some View {
ChecklistView()
.environmentObject(TitleModel())
}
}`