这是我用户登录时的Json请求。为了设置profileView,我需要更新UI,我在那里实例化下一个视图控制器。但是,在完全更新配置文件之前,我需要发出第二个JSON请求来获取图像。如果第一个JSON请求成功,我只能发出第二个JSON请求。在dispatch_async中创建另一个JSON请求是不好的做法吗?
jsonRequest.get(userCookie, url: userURL) { (succeedCookie: Bool, msg: String, results: Dictionary<String, Any>) -> () in
var gotUserInfo = false
if(succeedCookie) {
println("It twerked! - you got the cookie", error: msg)
}
else {
println(("It didn't twerk .. :( you no get cookie", error: msg))
}
// Move to the UI thread
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if gotUserInfo {
//
// Second JSON request goes here
//
let vcTwo = self.storyboard?.instantiateViewControllerWithIdentifier("userProfile") as ProfileViewController
//set future View variables here
self.navigationController?.pushViewController(vcTwo, animated: true)
}
})
}