URLSession.shared.dataTask(...)不起作用

时间:2017-02-07 21:58:48

标签: swift3 xcode8 nsurlsession shared

我找不到任何解决方案,请你帮帮我......

override func tableView(_ tableView: UITableView, cellForRowAt indexPath:   IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)

    let user = users[indexPath.row]

    cell.textLabel?.text = user.name

    cell.imageView?.image = UIImage(named: "lukas")

    if let profileImageURL = user.profileImageURL {
        var url = NSURL(string: profileImageURL)

        URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
            if error != nil {
                print(error)
                return
            }
        })
    }

    return cell
}

img

1 个答案:

答案 0 :(得分:0)

(Swift 3)编译器需要原生URL(不含NS

let url = URL(string: profileImageURL)