Noah Iarrobino
Noah Iarrobino

Reputation: 1553

Where should I load database values in iOS

I want to download data from my DB before my home screen loads, I currently am calling that function in func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool in my AppDelegate.Swift file, but that function does not get called before my Home screen's viewDidLoad() function, where is the fastest place to download database data in iOS?

Upvotes: 1

Views: 203

Answers (1)

Derick Mathews
Derick Mathews

Reputation: 467

I'm not 100% sure if this will work as I have not seen your code. If you are using Storyboard you can use the ViewWillLoad function. Swift UI only has a ViewDidLoad and no ViewWillLoad function to my knowledge; The best place in a SwiftUI application would be in your SceneDelegate in the func scene(...) right before let contentView = ContentView(). Here you can load your data and store it. This will allow you to load the data before anything is presented. This might cause the user to wait longer than usual for your data to load so you shouldn't ignore your LaunchScreen.

Upvotes: 1

Related Questions