request = Alamofire.request(.GET, recipe.foodImageUrl!).validate(contentType: ["image/*"]).response(completionHandler: { request, response, data, err in
if err == nil {
let img = UIImage(data: data!)!
self.foodRecipeImg.image = img
FeedVC.imageCache.setObject(img, forKey: recipe.foodImageUrl!)
}
})
运行此代码时,会出现一个错误,表示调用中有一个额外的参数。在查看其他答案后,我仍然无法找到解决方案。
答案 0 :(得分:0)
试试这个:
Alamofire 3:
let strURL = recipe.foodImageUrl ! as String
Alamofire.request(.GET, strURL).response { (request, response, data, error) in
if error == nil {
let img = UIImage(data: data!)!
self.foodRecipeImg.image = img
FeedVC.imageCache.setObject(img, forKey: recipe.foodImageUrl!)
}
}
Alamofire 4.0:
Alamofire.request(strURL).response { response in // method defaults to `.get`
if error == nil {
let img = UIImage(data: data!)!
self.foodRecipeImg.image = img
FeedVC.imageCache.setObject(img, forKey: recipe.foodImageUrl!)
}
}
答案 1 :(得分:0)
请尝试此变体。 (更新)
request = Alamofire.request(recipe.foodImageUrl!)
.response {
response in
let img = UIImage(data: response.data!)!
self.foodRecipeImg.image = img
FeedVC.imageCache.setObject(img, forKey: recipe.foodImageUrl!)
}