Picking up where we left off, I will wrap my ideas on @State & @Binding presented here.
Looking at ContentListView, I am kinda sorta grasping this a little better- follow me as I try to lead us to the 💡
In ContentListView, our @State property is recipeEditorConfig. We have the required default setting of us creating the object. Let’s take a look at this file, RecipeEditorConfig.
It is a ViewModel- or this struct is meant to help us organize our actions meant to happen in the view.
I guess reading this the first time, it all went over my head 🫨. Now, after the Nth try, the idea of @State is getting clearer. In Section 1 they start discussing RecipeEditorConfig but I like to look at where it is being accessed from first- it helps me understand the context a bit better. So on that other level, ContentListView, recipeEditorConfig is used for the Button behavior, also to present the sheet, and it is passed to the RecipeEditor. Below this, we have a private function that also uses recipeEditorConfig to determine ‘save this?’ with a conditional that helps us determine if the recipe is new, or just an update. Okay so what? @State manages “down flow” where the information is there, and the data flows down to the subviews. Click into RecipeEditor, and we can right away notice recipeEditorConfig has a different attribute- now this is a @Binding. What makes this important? The property config is the instance of RecipeEditorConfig, and its strength changes because now config cancels the action or confirms it as done. The result of this action changes everything, makes the whole view go away. Also @State has to have a default value and should be private. @Binding, from the example of this tutorial, should not be private. The information we receive needs to be injected from somewhere, and the information we deal with here, could blow everything up- feels like we are dealing with firecrackers more here
I guess I caught up to where they describe it in Section 2 🏃♂️➡️
Section 3 is where they caught up to me 😂 They discuss ContentListView, I couldn’t make sense of it- it made me want to look at the code for inspiration.
Maybe after reading it, it started to make sense in reverse, but I’m glad I took time to try and break it down. Hopefully some of y’all do as well.
