Silver Challenge - View Count doesn't persist

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?

When you change a persisted property you need to tell the persistent container context to save, similar to what PhotoStore does in fetchInterestingPhotos:

do {
    try self.persistentContainer.viewContext.save()
} catch {
    result = .failure(error)
}

That did it. Thanks again, Jon

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)")
        }
        
        if case .success = result {
            do {
                try self.store.persistentContainer.viewContext.save()
            } catch {
                print("Cannot save changes: \(error)")
            }
        }
        
    }

}