편집 호출되지 :을 내 시스템에서 스위프트 3.0 및 Alamofire 4.0스위프트 3 - 완료 핸들러가
를 사용하고 난 재료의 목록을 가지고, 각각의 물질은 번들 목록이 포함되어 있습니다. 이 번들을 webservice를 통해 요청하려고 시도하고 다음보기를 채 웁니다 (이 예제에서는 가져온 데이터 만 인쇄하려고합니다). 그러나 완료 처리기가 호출되지 않습니다 (ps : 초보자이고 처음입니다. 나는 async prog로 이끌고있다.) 왜 그런가?
WS에서 데이터를 가져 오는 기능은 다음과 같습니다
func fetchBundles(materialCode: String, completion: @escaping ([ProductsBundle]?) -> Void) {
var bundlesAdded = [ProductsBundle]()
let url = baseApiURL + "material-cavaletes/" + materialCode
print(url)
Alamofire.request(url, headers: headers).responseJSON {
response in
if let result = response.result.value {
var results = JSON(result)["results"]
for res in results {
bundlesAdded.append(self.getBundleFromJson(json: res))
}
completion(bundlesAdded)
}
}
}
그리고 함수 호출, 즉 데이터를 얻을보기를 업데이트해야한다 :
WebApi.sharedInstance.fetchBundles(materialCode: materialBeingListed.id, completion: {
(bundlesAdded: [ProductsBundle]?) in
guard let myBundles = bundlesAdded else {
print("erro")
return
}
print (myBundles)
})
내가에서 일부 중단 점을 넣어 "print (myBundles)"라는 행이 호출되지 않는다는 것을 알게되었습니다. 난 당신이 잘못 Alamofire 요청을 처리 할 수 있다고 생각하는 이유 ... :(
'responseJSON'에 전달 된 블록 안의 코드가 호출 되는가? 끝 점이 JSON 응답을 반환합니까? – crizzis
'앞에 let breakpoint result = response.result.value' Alamofire가 돌아 오는 지 알 수 있습니다. 그렇다면'print ("response : \ (response.response)")'를 추가해보십시오. 그것은 돌아오고 있습니다. 나는이 문제가'response.result.value'라고 내기 할 것이다. – Chris