I'm using Xcode 9, Swift 4.
I'm trying to show an image in ImageView from URL using below code :
func getImageFromUrl(sourceUrl: String) -> UIImage {
let url = URL(string: sourceUrl)
let dict = NSDictionary(contentsOf: url!)
let data = Data(dictionary: dict!)
let image = UIImage(data: data!)
return image
}
But I got an error in let image = UIImage(data: data!)
.
The compiler says :
Cannot convert value of type 'Data' to expected argument type 'Data'
What am I doing wrong?