これは、alamofireがzD.detail.append(p)に何かを追加する前にデータを非同期に読み込むために起こります。 ロードが完了するまで待機するプログラムの完了ハンドラを追加します。
その後
//here you call authenticateUser with a closure that prints responseObject
API().authenticateUser{ (responseObject, error) in
println(responseObject)
}
:詳細については
//authenticateUser receives your closure as a parameter
func authenticateUser(completionHandler: (responseObject: String?, error: NSError?) ->()) {
//it passes your closure to makeAuthenticateUserCall
makeAuthenticateUserCall(completionHandler)
}
//makeAuthenticateUserCall receives your closure
func makeAuthenticateUserCall(completionHandler: (responseObject: String?,
error: NSError?) ->()) {
Alamofire.request(.GET, loginUrlString)
.authenticate(user: "a", password: "b")
//here you pass a new closure to the responseString method
.responseString { request, response, responseString, responseError in
//in this closure body you call your completionHandler closure with the
//parameters passed by responseString and your code gets executed
//(that in your case just prints the responseObject)
completionHandler(responseObject: responseString as String!, error: responseError)
}
}
は、ドキュメントを読んで:Swift Closures
を、それは、製品= JSON(値)を聞かせてJSONをダウンロードし、すでにある –
うんだけでなく、あなたがコードに伝える必要がありますがalamofireがデータをロードするまで何も追加しないでください。それが終わったら、それを追加してデータをリロードすることができます。 – Dershowitz123
のように: func getZakazDetail(orderID:Int、tableView:UITableView、スピナー:UIActivityIndicatorView、完了:(JSON) - >())商品= JSON(値) 完了(製品) –