image(from url) with table cell

平成30年2月21日(水曜日)

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell: CustomCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
        
        if let data = tabledata {
            
            let urlString: NSString = data.results[indexPath.row].artworkUrl60 as NSString
            let imgURL: URL = URL(string: urlString as String)!
            do {
                    let imageData = try Data(contentsOf: imgURL as URL)
                    cell.img.image = UIImage(data: imageData)
            } catch {
                    print("Unable to load data: \(error)")
            }
        }
        return cell
    }

参考url
NSURL, URL and NSData, Data