Solution for Ch 22 Bronze Challenge: Photo View Count in Xcode 9.3


#1

Photorama.xcdatamodeld - Add attribute “viewCount” of type Integer 64 to Entity Photo

//  PhotoInfoViewController.swift

class PhotoInfoViewController: UIViewController {
...
  override func viewDidLoad() {
...
    photo.viewCount += 1
    try? photo.managedObjectContext?.save()

    let label = UILabel()
    label.text = "\(photo.viewCount) views"
    label.backgroundColor = UIColor.white
    label.translatesAutoresizingMaskIntoConstraints = false
    self.view.addSubview(label)

    label.trailingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: -8).isActive = true
    label.bottomAnchor.constraint(equalTo: imageView.bottomAnchor, constant: -8).isActive = true
  }
}