This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class URLImageTableViewCell: UITableViewCell { | |
@IBOutlet weak var urlImageView: UIImageView! | |
var urlImageLoader: DeinitBlock? | |
// new task is created, old task cancelled automatically | |
func setImage(url: URL) { | |
urlImageLoader = urlImageView.setCachedImage(url: url) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLSessionDataTask { | |
var cancellation: DeinitBlock { | |
return DeinitBlock { [weak self] in | |
self?.cancel() | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DeinitBlock { | |
let onDeinit: () -> Void | |
init(_ block: @escaping () -> Void) { | |
onDeinit = block | |
} | |
deinit { | |
onDeinit() | |
} | |
} |
NewerOlder