Hy guys,
I have these source code
let downloadTask = session.downloadTaskWithURL(url,
completionHandler: {
[weak button] url, response, error in
if error == nil && url != nil {
if let data = NSData(contentsOfURL: url) {
if let image = UIImage(data: data) {
dispatch_async(dispatch_get_main_queue()) {
if let button = button {
button.setImage(image, forState: .Normal)
}
}
}
}
This block of code try to put image from url in button element. Can someone help me to understand why in this source code block, in the completionHandler parameters list it use [weak button]? What's the meaning of [weak ...] and why use it? ( I think to avoid retain cycle.) Thank you guys!