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"
}
}