Swift 3: Display Image from URL

后端 未结 9 1857
Happy的楠姐
Happy的楠姐 2020-12-04 22:27

In Swift 3, I am trying to capture an image from the internet, and have these lines of code:

var catPictureURL = NSURL(fileURLWithPath: \"http://i.imgur.com/         


        
9条回答
  •  独厮守ぢ
    2020-12-04 22:37

    Using Alamofire worked out for me on Swift 3:

    Step 1:

    Integrate using pods.

    pod 'Alamofire', '~> 4.4'

    pod 'AlamofireImage', '~> 3.3'

    Step 2:

    import AlamofireImage

    import Alamofire

    Step 3:

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

提交回复
热议问题