答案 0 :(得分:1)
psCount是异步函数,因此您无法返回。如果socket.on还没有完成,但psCount仍然返回 你应该编码:
func psCount(handleFinish:((pCount:Int)->())){
socket.on("reply") { data, act in
let json = Json(data)
let pCount:Int = json[0].count
handleFinish(pCount: pCount:Int)
}
}
并称之为:
self.psCount { (pCount) -> () in
print(pCount)
}