在下面的代码中,我对“自我”实际引用的内容感到困惑。在Swift 3中,在这种情况下自我指的是什么对象
let imageURL = URL(string : “http://exampleURLh.jpg”)!
let task=imageDataURLSession.sharedSession().dataTaskWithURL(imageURL, {(data, response, error) in
print (“task finished”)
}
task.resume()
if error == nil {
let downloadedImage = UIImage(data: data!)
self.imageView.image = downloadedImage
}
我知道,我设置downloadedImage作为使用其图像属性ImageView的,但我不知道为什么需要自我,它拥有在这种情况下什么样的数据块。我知道它指的是正在处理的viewController类的实例,但是该实例是UIImage,downloadedImage还是示例URL中图像的资源数据?
此代码包含在哪个类中? – Carcigenicate
它指的是这个代码所在的类。 – rmaddy
可能是https://stackoverflow.com/questions/26835013/what-is-self-used-for-in-swift – rmaddy