Skip to content

Instantly share code, notes, and snippets.

@uc-compass-bot
Created October 15, 2019 14:25
Show Gist options
  • Save uc-compass-bot/820f39f0c66194e0d16c84b87ea87342 to your computer and use it in GitHub Desktop.
Save uc-compass-bot/820f39f0c66194e0d16c84b87ea87342 to your computer and use it in GitHub Desktop.
Example Of Retain Cycle On Closure #4 - Fix
class ViewController: UIViewController {
private var onTap: (() -> Void)?
override func viewDidLoad() {
onTap = { [weak self] in
self?.refreshTitle() // ✅ Doesn't capture self strongly
}
}
private func refreshTitle() {
title = "Refreshed"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment