How to load image in swift using Alamofire

后端 未结 9 903
醉话见心
醉话见心 2020-12-13 13:16

I have a collection view controller, which load image Async by URL. (Something like Instegram) I am looking for the best way to implement the part of the loading image. plea

9条回答
  •  囚心锁ツ
    2020-12-13 14:00

    You can download image by using responseData(queue:completionHandler:)

    SWIFT 4

    func downloadImages(imageURL: String) {
    
        Alamofire.request(imageURL, method: .get)
            .validate()
            .responseData(completionHandler: { (responseData) in
                self.yourImageVIew.image = UIImage(data: responseData.data!) 
                DispatchQueue.main.async {
                    // Refresh you views
                }
            })
    }
    

提交回复
热议问题