How can I solve this problem? Initializer for conditional binding must have Optional type, not 'String'
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.lblNamnEfternamn.text = personsArray[indexPath.row].wholeName
cell.lblEmail.text = personsArray[indexPath.row].email
cell.imageAvatar.image = UIImage(named: "avatar")
if let newProfileImageUrl = personsArray[indexPath.row].profileImageUrl {
let url = NSURL(string: newProfileImageUrl)
let request = URLRequest(url: url! as URL)
let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async {
cell.imageAvatar.image = UIImage(data: data!)
tableView.reloadData()
}
}
}
return cell
}