Search code examples
swiftparse-platformappdelegate

Get applicationDidFinishLaunching call in a View Controller. Parse not initialized yet


I am trying to load data from Parse in my Initial View Controller. The issue is that Parse is initialized in my AppDelegate's didFinishLaunching so I need to wait until it is called before I attempt to load the data from Parse. What is the best way to get this notification in my view controller? Or would it be better to get the data in my AppDelegate?

All help is appreciated!


Solution

  • You can add an observer for the UIApplicationDidFinishLaunchingNotification inside your view controller viewDidLoad method:

    NotificationCenter.default.addObserver(self, selector: #selector(didFinishLaunchingNotification), name: UIApplication.didFinishLaunchingNotification, object: nil)
    

    Add your method to the view controller

    @objc func didFinishLaunchingNotification(_ notification: Notification) {
        // your code
    }