A call to return the parent function from the completion handler

I have the function of performing network tasks in func application(application:didFinishLaunchingWithOptions launchOptions:). By default rootViewControllerit matters UITabBarController. I want to synchronize the list of my brands by downloading it from the server when the application starts. My code is as follows:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        self.tabBarController = self.window?.rootViewController as! UITabBarController
        .......
        .......
        .......

        APICaller.getBrandsAndOutletList(withAuthToken: "87087fa228dee4fbbacada66683eb6fa94d4d8968dbc8121d275afe75a79e4b6d",
            success: { (result) in
                let rCode = result["rcode"] as! String
                //If user revoked or access revoked for the user
                guard rCode == "200" else {
                    let updateAppVC = UpdateAppViewController(nibName: "UpdateAppViewController", bundle: NSBundle.mainBundle())
                    if rCode == "401" {
                        let userStatus = result["status"] as! String
                        print(userStatus)
                        updateAppVC.message = userStatus
                        updateAppVC.buttonTitle = "Re-login"
                        self.window?.rootViewController = updateAppVC
                        //POINT-1
                        return
                    }else {
                        updateAppVC.message = "Some error"
                        updateAppVC.buttonTitle = "Retry"
                        self.window?.rootViewController = updateAppVC
                        //POINT-2
                        return
                    }

                }

                let brands = result["brands"] as! [[String:AnyObject]]
                print(brands)
                //POINT-3

            }) { (errorMessage) in
                print(errorMessage)
                //POINT-4
        }

        return true //POINT-5
    }

A network request is currently in progress, and the list is loading in the background. Runs return trueand appears tabBar. Then, after the request is completed, success:or is called failure:.

What I want to achieve, I do not want return trueuntil the request is completed. Therefore, I do not want to call return truePOINT-5. Instead, I want to call it return truePOINT-1,2,3,4, that is, when my network request is complete. Can I do this, if so, how?

+4
1

.

, . , . , ( ) , .

+1

Source: https://habr.com/ru/post/1628610/


All Articles