Swift 3: Display Image from URL

后端 未结 9 1856
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:41

    let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg")
    let data = try? Data(contentsOf: url)
    
    if let imageData = data {
        let image = UIImage(data: imageData)
    }
    

提交回复
热议问题