Fetching data from one view, displaying it on another.

Good day,

I have hard data in the form of an array (which will eventually be replaced by a CMS) on one view. This view creates card like tiles that displays a bit of data from that array list items. I then would like to display that data in full again, in a different view when the user clicks on one of the tiles. I am very very new to SwiftUI, please forgive me.

I believe that I must use @ObservableObject and @ObservedObject, but I am unsure how to apply it. Below is a code snippet...

Code Block swiftui
var draftData = [
Draft( title: "Beer 1", type: "NEIPA 7.5%", desc: "This beer x y z 1 2 3 description here."),
Draft( title: "Beer 1", type: "NEIPA 7.5%", desc: "This beer x y z 1 2 3 description here."),
Draft( title: "Beer 1", type: "NEIPA 7.5%", desc: "This beer x y z 1 2 3 description here."),
]


Now, in the view that this is in I can simply just define that those items are strings, then call them as shown below, but I am unsure how I could call it on a whole different view?
Code Block
Text(draft.title)

I strongly suggest you watch the first 3 vidoes in the series from Stanford University
Search on Youtube for Stanford CS193p

Those will give you a fantastic start to SwiftUI and the MVVM paradigm.

Let us know hw you get on!
So I have made it through the first two videos (Lectures 1 & 2). I recently did a large portion of a tutorial that I paid quite a bit of money for, I'm afraid I wasted my money. This basic approach changed quite a bit of my views on how to construct applications... if what I've gathered is correct then the following applies..
  • 1 View - This is what the user sees.

  • Numerous View Models - This is what handles the interpretation of what is going on behind the scenes and what the user gets to see.

  • Model - This is what is going on behind the scenes, this is your back end data.

Now my questions are... do you have multiple models / back end data files? How would you decide what is what? Also, how do you decide what view models you will use and so on?

Your response was both a blessing and a curse as it will likely cause me to recreate my entire app lol
Fetching data from one view, displaying it on another.
 
 
Q