From e3e74d9075d8fdcc9467c5f9d1c13b69ad4a16ea Mon Sep 17 00:00:00 2001 From: Brent Mifsud Date: Sat, 1 Jun 2019 15:18:54 -0400 Subject: [PATCH] fix issue #15 - Use Weak self when loading image in detail view - https://github.com/udacity/ios-nd-networking/issues/15 --- .../Controller/MovieDetailViewController.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TheMovieManager/Controller/MovieDetailViewController.swift b/TheMovieManager/Controller/MovieDetailViewController.swift index 4f87c70..e4e8a0f 100644 --- a/TheMovieManager/Controller/MovieDetailViewController.swift +++ b/TheMovieManager/Controller/MovieDetailViewController.swift @@ -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 { @@ -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) @@ -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) } } }