0

I am storing URLs as Strings in an Organization. These URLs are used to fetch each Organization's logo and display it in a tableview. Here is the code I am using to do this:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "orgcell", for: indexPath) as! OrgCell

    cell.orgAcro.text = filteredOrgs[indexPath.row].acronym
    cell.topTag.text = filteredOrgs[indexPath.row].tags[0].title
    let data = try? Data(contentsOf: filteredOrgs[indexPath.row].url)
    if (data == nil) {
        cell.orgImg.image = UIImage()
    } else {
        cell.orgImg.image = UIImage(data: data!)
    }
    return cell

}

The only URL this is working for is this one https://pbs.twimg.com/profile_images/718076464856338432/zlcMj0Oo.jpg

It is not working for this one http://www.therightfew.com/wp-content/uploads/2016/09/Planned-Parenthood-Logo-Square.jpg
It has nothing to do with the order by which I load them, I have tried switching it up. Any ideas as to what's going on?

Gabe Spound
  • 146
  • 2
  • 14
  • 2
    The difference is that one is HTTPS and the other one it is not. You need to edit your info plist, add APP Transport Security key and the website domain to the exception list or allow arbitrary downloads. BTW you should take a look at this UIImageView extension http://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift/27712427#27712427 – Leo Dabus Feb 01 '17 at 00:37
  • 1
    I'll preemptively tell you to research how to lead an image on a background thread. If you don't, your UI will get laggy. – AdamPro13 Feb 01 '17 at 00:45
  • Use AlamofireImage or SDWebImage for this or you will have severe stutter since your Data call is blocking the main thread. https://github.com/Alamofire/AlamofireImage https://github.com/rs/SDWebImage – Josh Homann Feb 01 '17 at 02:07

0 Answers0