Call function in ViewController from AppDelegate (tabbed app)


Swift • Xcode

Code for the AppDelegate.swift file

    func applicationWillEnterForeground(_ application: UIApplication) {
      // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

      let myTabBar = self.window?.rootViewController as! UITabBarController     //Getting the tabbar
      myTabBar.selectedIndex = 0                                                                                   //select the tab, 0,1,2,3,etc
      let tmpVC = myTabBar.selectedViewController as! ViewController
      tmpVC.functionToCall()
      
    }

Written by fbrefere001

Posted by fbrefere001 on Sunday January 21, 2018