У меня есть и проблема на линии
'URLSession.shared.dataTask (с: url! {(Данные, ответ, ошибка) в'
с кодом ошибки: невозможно вызвать значение нефункционального типа 'NSURL'
Я посмотрел вокруг и по-разному попробовал это, и все равно выдает ошибку даже при установке URL в качестве типа URL, а не NSURL. Если кто-то может помочь, это было бы удивительно! Код будет ниже:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellID)
let user = users[indexPath.row]
cell.textLabel?.text = user.name
cell.detailTextLabel?.text = user.email
//cell.imageView?.image = UIImage(named: "defaultpropic")
cell.imageView?.layer.cornerRadius = 30
cell.imageView?.layer.masksToBounds = true
if let profileImageUrl = user.profileImageURL
{
let url = NSURL(string: profileImageUrl)
URLSession.shared.dataTask(with: url! { (data, response, error) in
//download hit error
if error != nil
{
print(error)
return
}
DispatchQueue.main.async
{
cell.imageView?.image = UIImage(data: data!)
}
}).resume()
}
return cell
}
Площадь ошибки ниже:
if let profileImageUrl = user.profileImageURL
{
let url = NSURL(string: profileImageUrl)
URLSession.shared.dataTask(with: url! { (data, response, error) in //<- Error Here
//download hit error
if error != nil
{
print(error)
return
}
DispatchQueue.main.async
{
cell.imageView?.image = UIImage(data: data!)
}
Это должно позволить мне установить уникальный профильPic для каждого пользователя.