Show image in UIImageview by using alamofireimage

2.3k views Asked by At

It seems to be a silly question, but I'm pretty new with Swift.

I want to download PNG image from https://httpbin.org/image/png and make it show in my UIImageView which has the name imageView, but it's not working.

[Result]: SUCCESS: , {33.333333333333336, 33.333333333333336} [Timeline]: Timeline: { "Request Start Time": 527346831.982, "Initial Response Time": 527346833.435, "Request Completed Time": 527346833.437, "Serialization Completed Time": 527346833.468, "Latency": 1.453 secs, "Request Duration": 1.455 secs, "Serialization Duration": 0.031 secs, "Total Duration": 1.486 secs } SUCCESS: , {33.333333333333336, 33.333333333333336} image downloaded: , {33.333333333333336, 33.333333333333336}

import UIKit
import Alamofire
import AlamofireImage

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()


    Alamofire.request("https://httpbin.org/image/png").responseImage { response in
        debugPrint(response)

        debugPrint(response.result)

        if let imageView = response.result.value {
            print("image downloaded: \(imageView)")


        }
    }     
}
}
1

There are 1 answers

0
Tamás Sengel On BEST ANSWER

You did not set the image as your imageView's image. Here is your code, fixed:

Alamofire.request("https://httpbin.org/image/png").responseImage { response in
    if let image = response.result.value {
        self.imageView.image = image
    }
}