Chapter 30: Image Picker UIKit Apprentice

Xcode 12.3/MacOS 10.15.7/iOS 14.3 on iPhone 11 and iPad Air 2
Completed My Locations tutorial in UIKit Apprentice. Tested app with success on SE(2nd Generation) and iPad 9.7 in. simulators. Tested on my iPhone 11 with success. Crashed my iPad Air 2 when I tried to add a photo to the location. I tried running the Chapter 31 Final version on my iPad Air 2 with the same result. I attached the error image. Can anyone help resolve this?


Hi @brozelle,

Sorry about that. The issue is an iPad-specific one where you get a crash when you try to display an alert because on iPad, the alert has to be done via a popover.

So, in showPhotoMenu in LocationDetailsViewController.swift, you would need to add the following lines before you present the alert:

    // New code
    if let ppc = alert.popoverPresentationController {
      ppc.barButtonItem = navigationItem.rightBarButtonItem
    // End new code
    present(alert, animated: true, completion: nil)

The above should prevent the crash that you’re experiencing.