如何将 NSURL 类型的值赋值给 UIimage 类型?

How to assign value of type NSURL to type UIimage?

您好,我有一个 Json 文件:

{
   "Name":"Car",
   "Picture":"http://www.starpropertiesindia.com/blog/wp-content/uploads/2016/08/kochi1.jpg",
   "Description":"Ford"
}

在 Table 视图控制器中读取名称图片和描述。

我的TableViewController中有这个代码:

let name = aFruit["Name"].stringValue
let imageURL = aFruit["Picture"].stringValue
let description = aFruit["Description"].stringValue

现在我想 return 它们进入 Table 视图单元格。对于这种情况,我使用此代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as!  TableViewCell
    let fruit = fruits[indexPath.row]
    cell.CellTitle.text = fruit.name
    cell.CellDescription.text = fruit.description
    cell.CellImage.image = fruit.imageURL
    return cell
}

一切都非常适合

cell.CellTitle.text = fruit.name

cell.CellDescription.text = fruit.description

但是当我写

cell.CellImage.image = fruit.imageURL

它给我一个错误:

Cannot assign value of type NSURL to type UIimage !

这里可能有什么错误?

试试这样的东西...我还没有测试过。

let image = UIImage(data: NSData(contentsOf: NSURL(string: fruit.imageURL)))