TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Order of Loading

Forums > SwiftUI

I'm new to asking questions on these sorts of forums so apologies if this is an inappropriate place. I want to be respectful of the fact that this is just for Swift and not Firebase, but I think this is a Swift question:

I'm trying to access data from Firebase. The data is collected from FB and added to a list (which is just how the data has to be retrieved to my knowledge). Changing nothing about the 'call' function, sometimes the program runs and displays the information, and sometimes it doesn't. It seems to be an initialization issue: For the sake of this discussion I have five 'main' pages in my app and ten 'subordinate' pages which can be clicked into from the five main pages. When the FB data is inserted on one of the 'main' pages, the app crashes with an lldb error, because the list is not yet populated, however, copying the same code onto a 'subordinate' page (see below) it runs just fine. This leads me to assume that the main pages populate before the init functions are called, but before the subordinate pages are populated. How do I address this?

I tried putting the init function into Content View because that loaded before anything else

Sorry, again, if this is inappropriate to ask, I've been banging my head against the wall on this for the better part of two days. I think it's a Swift-side problem

struct TestDeck2: View {

@ObservedObject var genFs = GenFuncs()

init() {
    genFs.UsrCoreInfoList()
}

var body: some View {

    VStack{
        Text("\(genFs.UsrCorInfL[0].FirstN)")

        Button(action:{ print("Fill"); print("\(genFs.UsrCorInfL[0].IGCbal)") } ) //addFN(FN: FNo, H_1url: H_1url_out ) } )
        {Image(systemName:"water.waves")}

        }
    }
}

2      

@Bnerd  

It sounds like you are truing to populate your view before the information is available. instead of init try to make a Async func

func UsrCoreInfoList() async {
//Your code here.
...
}

Then you call it on the view you want using .task , i.e.

var body: some View {

    VStack{
        //Your code here
        ...
        }.task {
        await genFs.UsrCoreInfoList() 
        }
    }
}

2      

Wonderful! thank you, I had tried async but had gotten the view order incorrect.

Thank you again, and what a delightful avatar!

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.