0
저는 KolodaView를 구현하고 있습니다 : https://github.com/Yalantis/Koloda. viewForCardAt
함수는 UIView
을 반환하고 내 UIView
에는 다운로드해야하는 이미지가 있습니다. 문제는 함수 자체가 UIView
의 반환 유형을 예상하지만 setupCard
메서드의 완료 블록이 실행되면 알 수있는 방법이 없으므로 완료 블록에서 대신 빈 을 반환 할 수 있습니다. . 완료 블록에 return a
을 추가하려고 시도했지만 허용되지 않습니다. 완료 블록이 실행 된 후에 만 카드가 반환되도록 아래 코드를 어떻게 변경합니까?Completion Block Swift에서 돌아 가기
func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
var a = FlatCard()
if let listings = all_listings {
if index < listings.count {
setupCard(index: index, listings: listings, { (complete, card) in
if (complete) {
a = card
}
})
return a
}
}
return a
}
func setupCard(index: Int, listings : [Listing], _ completionHandler: @escaping (_ complete: Bool, _ card : FlatCard) ->()) ->(){
let curr_card = FlatCard()
if let main_photo_url = listings[index].pic1url {
URLSession.shared.dataTask(with: main_photo_url, completionHandler: { (data, response, error) in
if (error != nil) {
print(error)
return
}
DispatchQueue.main.async {
curr_card.mainFlatImage = UIImage(data: data!)
}
})
completionHandler(true,curr_card)
return
} else {
completionHandler(true,curr_card)
return
}
}
FlatCard''무엇인가? –