0

I have a somewhat peculiar "problem" - the app I'm working in is not crashing. I'm learning iOS development and following this tutorial on Apple's website. At one point, you are instructed to run your app (which tries to access the user's photo library) without having asked for permission or put a description in the .plist file. According to the tutorial, the app is expected to crash with SIGABRT, but mine ran without complaint. I am using xCode 9, iOS 11, and SWIFT 4 and the tutorial is written with xCode 8, iOS 10, and SWIFT 3.

Does anyone know why this isn't crashing? Is it due to some change between iOS 10 and 11 that I should know about going forward? Or perhaps a change to the simulator in xCode 9?

I'm just trying to make sure this difference in behavior isn't the tip of some conceptual iceberg I'm missing. I've tried to find answers online, but not a lot of folks seem to complain about their code working so there hasn't been much to go on.

Here's the code for my ViewController in case it helps, but my instinct is that the difference is probably not related to my code specifically:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    // MARK: Properties

    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!
    @IBOutlet weak var photoImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        //Handle the text field's user input through delegate callbacks
        nameTextField.delegate = self
    }

    // MARK: UITextFieldDelegate

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        //Hides the keyboard
        textField.resignFirstResponder()
        return true
    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        mealNameLabel.text = nameTextField.text
        nameTextField.text = nil
    }

    // MARK: UIImagePickerControllerDelegate:

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        //Dismiss the picker
        dismiss(animated: true, completion: nil)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        //The image dictionary may contain multiple representations of the user's chosen image, but we will use the original. Make sure the image exists:
        guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else{
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        }
        //Set the image for photoImageView to the selected image
        photoImageView.image = selectedImage
        //Dismiss the picker
        dismiss(animated: true, completion: nil)
    }

    // MARK: Actions

    @IBAction func imageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {
        //Hide the keyboard
        nameTextField.resignFirstResponder()

        //Creates a view controller that will allow the user to choose a photo
        let imagePickerController = UIImagePickerController()

        //Allows user to choose a photo from their photo library
        imagePickerController.sourceType = .photoLibrary

        //Make sure this view controller will get notified when the user chooses a picture
        imagePickerController.delegate = self
        present(imagePickerController, animated: true, completion: nil)
    }

    @IBAction func setDefaultTextLabel(_ sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}
  • Running on the simulator. – Christopher Thiebaut Dec 04 '17 at 03:58
  • I did not start by downloading their source. Their source is only available for download so you can check your work at the end. – Christopher Thiebaut Dec 04 '17 at 04:04
  • @AllenHumphreys, thanks, that's helpful. – Christopher Thiebaut Dec 04 '17 at 04:10
  • This is a dup. I remember watch a WWDC session where people literally applauded when they heard about the change in iOS 11. Short answer? *Yes*, no plist privacy entry is needed - provided you are only targeting iOS 11. (The privacy plist for camera is still needed though.) See the accepted answer on my dup target for a full explanation. –  Dec 04 '17 at 04:12
  • @dfd You're right, I hadn't found that post. Conceptually, this really is a duplicate of that. Thanks for pointing that out, now I understand what's happening. – Christopher Thiebaut Dec 04 '17 at 04:13
  • No problem. I was composing an answer but couldn't find any good Apple documentation - nor could I remember the specific WWDC session. It's a pretty obscure change, one that would have thrown me too. I think you should leave this question up, as it can point to a good answer for others. –  Dec 04 '17 at 04:15
  • @ChristopherThiebaut I didn't realize this change happened in iOS 11. If you install an iOS 10 simulator (Xcode preferences), you can see the crash the tutorial is mentioning. – allenh Dec 04 '17 at 13:54

0 Answers0