I'm trying to enable offline data with my firebase database. Unfortunately when running this code, it tells me that 'Calls to setPersistenceEnabled must be made before any other usage of FIRDatabase instance.' I believe this is because firebase calls are asynchronous, but I can't figure out how to fix the issue.

from my AppDelegate:

//Firebase database let myDatabase = Database.database().reference() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. //Firebase FirebaseApp.configure() Database.database().isPersistenceEnabled = true //check if user is already logged in if Auth.auth().currentUser != nil { let storyboard = UIStoryboard(name: "Main", bundle: nil) self.window?.rootViewController = storyboard.instantiateViewController(withIdentifier: "signedIn") } else { // No user is signed in. Directs to Login/Register view. } return true }

I've tried commenting out the check user login portion in case Auth.auth() was messing it up, but it didn't fix it. Should I be putting some of these things elsewhere instead of my AppDelegate?