Reputation: 83
I've got the following error:
with Xcode-beta 5 and Swift. In beta 4 it works fine. Anybody who can help me?
extension UIImageView {
public func imageFromUrl(_ urlString: String) {
if let url = URL(string: urlString) {
let request = URLRequest(url: url)
NSURLConnection.sendAsynchronousRequest(request, queue: OperationQueue.main) {
(response: URLResponse?, data: Data?, error: NSError?) -> Void in
self.image = UIImage(data: data!)
}
}
}
}
Upvotes: 2
Views: 3059
Reputation: 318774
Read the error. Look as the type of your error
parameter. You've declared it as NSError
but the error message is telling you that it should be declared as Error
, not NSError
.
So you code should be:
extension UIImageView {
public func imageFromUrl(_ urlString: String) {
if let url = URL(string: urlString) {
let request = URLRequest(url: url)
NSURLConnection.sendAsynchronousRequest(request, queue: OperationQueue.main) {
(response: URLResponse?, data: Data?, error: Error?) -> Void in
self.image = UIImage(data: data!)
}
}
}
}
Upvotes: 4