I have textfields that are a couple views deep. I am trying to pull the inputed data to send to a server. Has anyone found an example of pulling data that is deep nested in views?
Here is the structure of this feature..
symbol: > NavigationLink
symbol: ~ Subview
HostingViewController ~ CustomListView > FormTypeView > BuildFormView (Has ObservedObject constructed here) ~ ViewPagerView (Horizontal List Of PageViews) ~ FourItemCardView ~ TextFieldInputView.
Alternate Structure Outline to help explain
- HostingViewController ~ CustomListView - FormTypeView - BuildFormView ~ ViewPagerView ~ FourItemCardView ~ TextFieldInputView
When you click "Add" in the ListView, you choose from a form type, and then the BuildFormView creates a multi-card swipe-able view pager. This is built inside ObservableObject.
In a perfect world all my data would bind to..
@Published var pageCells: [PageViewCell] = [PageViewCell]()
Where I could call it in ObservableObject's buildFormData1()..
let headline: String = pageCells[0].valueOne
let location: String = pageCells[0].valueTwo
let isPrivate: String = pageCells[0].valueFour
I have managed view binding in swiftui, and callbacks upon a button press, but to bind a view or callback 2-3 levels doesn't seem to work.
I have tried EnvironmentalObject which sort of breaks. I can't use it in SceneDelegate since I have my HostingViewController in storyboard. I can define it where I connect the CustomListView to the HostingViewController, but that crashes ( can't remember the reason off my head ). Even if this did work to obtain the data specific would be difficult. As my view pager is dynamically changing I can't individually define every variable in my ObservedObject.
Has anyone found an example of pulling data that is deep nested? I can't avoid the nesting either because SwiftUI breaks (a misleading error) whenever you have too many views. Also let me know what code to post since there is a ton I could post which might over complicate this question.
