Skip to content

Commit

Permalink
fix issue #15 - Use Weak self when loading image in detail view - uda…
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Mifsud committed Jun 2, 2019
1 parent e0410ba commit e3e74d9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions TheMovieManager/Controller/MovieDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MovieDetailViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var watchlistBarButtonItem: UIBarButtonItem!
@IBOutlet weak var favoriteBarButtonItem: UIBarButtonItem!

var movie: Movie!

var isWatchlist: Bool {
Expand All @@ -31,7 +31,7 @@ class MovieDetailViewController: UIViewController {
imageView.image = UIImage(named: "PosterPlaceholder")

TMDBClient.downloadPosterImage(posterPath: movie.posterPath ?? "", completion: handlePosterImageResponse(data:error:))

toggleBarButton(watchlistBarButtonItem, enabled: isWatchlist)
toggleBarButton(favoriteBarButtonItem, enabled: isFavorite)

Expand Down Expand Up @@ -83,8 +83,10 @@ extension MovieDetailViewController {
func handlePosterImageResponse(data: Data?,error: Error?) {
guard let data = data else { return }

weak var movieDetailVC = self

DispatchQueue.main.async {
self.imageView.image = UIImage(data: data)
movieDetailVC?.imageView.image = UIImage(data: data)
}
}
}

0 comments on commit e3e74d9

Please sign in to comment.