Group Group Group Group Group Group Group Group Group

Chapter 30: Image Picker - Understanding how an error was determined - pg 712

#1

I’m looking for clarification as to how someone determines what line of code is causing an error in their app. More specifically, in Chapter 30: Image Picker - pg 712.

Here, we test the app in the simulator, and the camera should open using our new takePhotoWithCamera() method. However, the app crashes - which the book mentions will happen. It crashes with the following error:

 *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Source type 1 not available'

The book immediately explains that the culprit for the crash is the line:

imagePicker.sourceType = .camera

The books then explains that this happens because not all devices have a camera. Fair enough. But my question is how would I as a new developer know that it was that particular line that caused my problem? All I’m directed to is that wildly generic AppDelegate SIGABRT error.

I would love it if someone could shed some light on this.

#2

I’ve gone around that block a few times. Usually you first figure out what you did that triggered the crash. In this case, you tapped something that called takePhotoWithCamera().

So go to your code, and set a breakpoint on the first line of takePhotoWithCamera. Run again, tap again, and it should stop on that line. Then tap the StepOver button, and see if the first line executes okay. If it does, tap StepOver again and see if the second line executes okay. If you keep doing that, you will discover which line triggers the crash.

The exception message ‘Source type 1 not available’ is a hint as well, especially if you have a line that is setting the sourceType property of something.

#3

Thanks @sgerrard I’ll give that a try!