如何从downloadedImage
返回beginGetImageRequest
。
func beginGetImageRequest() {
if let imagePath = thumbPath {
request = Alamofire.request(.GET, imagePath).response(completionHandler: { (_, _, imageData, error) -> Void in
if error != nil {
NSLog("Error downloading thumbnail image: \(error)")
} else {
if let downloadedImage = UIImage(data: imageData!) {
self.imageView.image = downloadedImage
}
}
})
}
}
答案 0 :(得分:0)
误解了请求,我将其编辑为agian:
func beginGetImageRequest(completion:(_ image:UIImage)->()){
if let imagePath = thumbPath {
request = Alamofire.request(.GET, imagePath).response(completionHandler: { (_, _, imageData, error) -> Void in
if error != nil {
NSLog("Error downloading thumbnail image: \(error)")
} else {
if let downloadedImage = UIImage(data: imageData!) {
completion(downloadedImage)
}
}
})
}
}
调用方法时:
beginGetImageRequest { (image:UIImage) in
// code you need
}