Я нашел решение для своего случая
ForEach(myProducts.indices){ index in
Toggle(isOn:
Binding<Bool>
(get: {return self.myProducts[index].productStatus},
set: { p in self.myProducts[index].productStatus = p}
)) {
Text(self.myProducts[index].productName)
}
.onTapGesture {
self.myProducts[index].productStatus.toggle()
do{
try self.managedObjectContext.save()
}catch{
print(error)
}
}
}
Только я не понимаю одну строчку кода: set: {p in self.myProducts [index] .productStatus = p}
Кто-нибудь может мне объяснить?