1. do, catch
let url = URL(string: user.imageURL)
do {
let data = try Data(contentsOf: url!)
let image = UIImage(data: data)
}catch let err {
print("Error : \(err.localizedDescription)")
}
2. URLSession
if let image = imageURL {
let url = URL(string: image)
URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async {
imageView.image = UIImage(data: data!)
}
}).resume()
}