小编bri*_*n S的帖子

等到异步api调用完成 - Swift/IOS

我正在开发一个ios应用程序,appDelegate我的内容是:

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {    
    self.api.signInWithToken(emailstring, token: authtokenstring) {
        (object: AnyObject?, error:String?) in            
            if(object != nil){
                self.user = object as? User
                // go straight to the home view if auth succeeded
                var rootViewController = self.window!.rootViewController as UINavigationController
                let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                var homeViewController = mainStoryboard.instantiateViewControllerWithIdentifier("HomeViewController") as HomeViewControllerenter
                // code here
                rootViewController.pushViewController(homeViewController, animated: true)
            }
        }
    return true
}
Run Code Online (Sandbox Code Playgroud)

api.signInWithToken是一个用Alamofire进行的异步调用,我想在func应用程序的最后一端返回true之前等待它的完成.

closures swift

5
推荐指数
1
解决办法
9499
查看次数

标签 统计

closures ×1

swift ×1