NEW: Learn SwiftData for free with my all-new book! >>

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!


Hacking with Swift is sponsored by Swiftable

SPONSORED An iOS conference hosted in Buenos Aires, Argentina – join us for the third edition from November 29th to December 1st!

Get your ticket

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.