MattBlack MattBlack - 1 year ago 138
Swift Question

Swift Image from URL

I am trying to display an image from a URL in swift using the code below but nothing appears.

let url = NSURL(string: "")
if let data = NSData(contentsOf: url as! URL) {
cell.imgCarNane.image = UIImage(data: data as Data)

The odd thing is that if I substitute the image for a jpeg hosted on a different site like:

it displays fine.

Is there something about the image I am trying to use that would be causing the issue?

if someone could take a look I would be very greatful.


Answer Source

I don't know why since the website you're retrieving the image from is using https (and seems secured), but you have to add the website (or allow arbitrary loads) in your plist.

Create an entry App Transport Security Settings

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download