BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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() {

var body: some View {


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




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 {

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


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

Thank you again, and what a delightful avatar!


Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.