使用夫特我可以像以下回調:夫特回調內聯函數用法
userService.validateToken("6beba35f", success: onSuccess, failure: onFailure)
func onSuccess(status_code: Int, data: String)
{
var dd : String = ""
}
func onFailure(status_code: Int, data: String)
{
var dd : String = ""
}
,但我想有在同一行作爲該呼叫的功能:
實施例1:
userService.validateToken("6beba35f",
success: (Int, String) ->()
{
},
failure: (Int, String) ->()
{
})
實施例2:
userService.validateToken("6beba35f",
success: (Int, String)
{
},
failure: (Int, String)
{
})
都給出錯誤。我認爲,即時通訊緊密與例1,但它不斷給我一個錯誤「預期,分隔符」當我把它添加「」
success: (Int, String), ->()
但錯誤口口聲聲說‘預計,分隔符’
任何想法是什麼解決方案?
包括函數
func validateToken(token: String, success: (Int, String) -> Void, failure: (Int, String) -> Void)
{
if(Network.isOnline())
{
var url: String = Commons.plistValue("Base URL") + "/security/" + token
Alamofire.request(.GET, url)
.responseJSON { (request, response, json, error) in
let jsonData: JSON = JSON(json!)
let statusCode: Int = response!.statusCode
if(statusCode == 202)
{
success(statusCode, jsonData["status"]["message"].stringValue)
}
else
{
failure(statusCode, jsonData["status"]["message"].stringValue)
}
}
}
else
{
failure(-1, "No Internet Connection")
}
}
使用修復
userService.validateToken("6beba35f",
success: { status_code, data in
(
println(status_code)
)
},
failure: { status_code, data in
(
println(status_code)
)
})
我包含了validateToken函數 – adviner
你有沒有試過'{status_code,數據在(代碼在這裏)}'? – zneak
OMG你的男人。非常感謝 – adviner