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
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
return
}else {
updateAppVC.message = "Some error"
updateAppVC.buttonTitle = "Retry"
self.window?.rootViewController = updateAppVC
return
}
}
let brands = result["brands"] as! [[String:AnyObject]]
print(brands)
}) { (errorMessage) in
print(errorMessage)
}
return true
}
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?