I can get a photo’s view count to persist while the app still runs (i.e. - if I jump from one photo to another and return to previous photos). But the view counts reset when I close and re-launch the app.
class PhotoInfoViewController: UIViewController {
// MARK: - Declarations
@IBOutlet var imageView: UIImageView!
@IBOutlet var numberOfViews: UILabel! // Silver Challenge
override func viewDidLoad() {
super.viewDidLoad()
store.fetchImage(for: photo) { (result) -> Void in
switch result {
case let .success(image):
self.imageView.image = image
self.photo.viewCount += 1
if self.photo.viewCount == Int16(1) {
self.numberOfViews.text = "\(self.photo.viewCount) View"
} else {
self.numberOfViews.text = "\(self.photo.viewCount) Views"
}
case let .failure(error):
print("Error fetching image for photo: \(error)")
}
}
}
Do I need to make adjustments elsewhere as part of this implementation?