UIImageView images are not loading either with downloading with Alamofire or using URL to convert to a data object and convert data object to a UIImage. My images on UITableViewCells are working but not the UIImageviews standalone in a UIView. It is giving me a blank.
UIImageViews: They are a subview of a UIView which is a subview of a UITableView
Here it is the code that Im using:
let imageURL = URL(string: _imageUrl)
let imageData = try? Data(contentsOf: imageURL!)
imageView.image = UIImage(data: imageData!)
Here is the extension that I'm using with Alamofire:
extension UIImageView {
func donwloadImageFrom(_ imageURL: String, contentMode: UIViewContentMode) {
let stringUrl = URL(string: imageURL)!
Alamofire.request(stringUrl, method: .get).response(completionHandler: { response in
if let imageData = response.data {
DispatchQueue.main.async(execute: {
self.contentMode = contentMode
self.image = UIImage(data: imageData)
})
}
})
}
}