In this post, we will see how to resolve Binding didSet variable to update computed var
Question:I am creating a nutrition tracker where I need the nutrients to update when the amount of the food is changed. This is dictated by the nutrition in the food and the amount eaten (obviously). I am trying to have my computed var (nutrients) update when the amount changes but what I have so far just reinitializes the object’s amount back to 1 instead of what is set in the Binding textfield.
There is also a measurement selector that needs to update and set the nutrient values but for the sake of simplicity I have just included the amount field. Can someone tell me where my thinking is wrong?
Best Answer:Your syntax is slightly off when you pass in the new nutrient values:
0 * amount(which of course is always 0). Adding parentheses should fix your issue:
If you have better answer, please add a comment about this, thank you!