0
我在一箇中心點(班級)工作,在那裏我的數據被請求和檢索。Swift - Grand Central Dispatch Class
這個類可以從任何觀點被稱爲:
override func viewDidLoad() {
super.viewDidLoad()
let group = dispatch_group_create()
var data = RestApiManager(group)
dispatch_group_notify(group, dispatch_get_main_queue()) {
return data
}
}
class RestApiManager {
let user = "user"
let password = "password"
var result: JSON = []
init(group) {
dispatch_group_enter(group)
Alamofire.request(.GET, "http://example.com/api/")
.authenticate(user: user, password: password)
.responseJSON { _, _, result in
switch result {
case .Success(let data):
self.result[] = JSON(data)
case .Failure(_, let error):
print("Request failed with error: \(error)")
}
dispatch_group_leave(group)
}
}
}
但初始化類時,它已經失敗。
任何人都可以幫助我設計一個合適的方式?
感謝和問候