Skip to content

Instantly share code, notes, and snippets.

@sisoje
Last active February 1, 2019 13:47
Show Gist options
  • Save sisoje/9f29fe20d89e1c30e0572449692bab74 to your computer and use it in GitHub Desktop.
Save sisoje/9f29fe20d89e1c30e0572449692bab74 to your computer and use it in GitHub Desktop.
Resource acquisition is initialization (RAII) in Swift: Example
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment