Store Search - Chapter 36 : Section : Download the artwork

I am trying to use UIImageView extension in my project.

extension UIImageView {
func loadImage(url: URL) → URLSessionDownloadTask {
let session = URLSession.shared
let downloadTask = session.downloadTask(with: url, completionHandler: { [weak self] url, response, error in
if error == nil, let url = url, let data = try? Data(contentsOf: url), let image = UIImage(data: data) {
DispatchQueue.main.async {
if let weakSelf = self {
weakSelf.image = image
}
}
}
})
downloadTask.resume()
return downloadTask
}
}

But i get following error at Data(contentsOf: url) line
Error Says : Argument labels ‘(contentsOf:)’ do not match any available overloads at Line No:5

Any idea how to fix this error ? I am using XCode 9.4.1

Hi @ravikanth_m, have you tried using a do catch for error handling?

Best,
Gina

This topic was automatically closed after 166 days. New replies are no longer allowed.