1

Is there a way to find out which object is Nil? I get these errors from time to time while coding and normally I have no trouble finding them because I test my code frequently.


Old question and deserved a clean up / extra info.

At the time I asked this, I had no real grasp of what optionals were. If you are having the error stated in the title, read up on optionals and unwrapping them. Basically use guard let and if let statements.

If you are here because you simple don't know how to use the debug tools in Xcode, the answers below show screenshots of where to go. The left screen at the bottom shows a list of values, one of them will be Nil

R Menke
  • 8,183
  • 4
  • 35
  • 63

2 Answers2

3

When you run into this error you should be able to browse through current assigned values in the box in the picture below. look at the box on the bottom left, you can look at any currently assigned value at the time of error. in this case the error is from attempting to read from a file that does not exist

Here is a better example enter image description here

nsij22
  • 869
  • 10
  • 20
  • Thanks! I didn't know that. Never had an error before that wasn't self explanatory, or that I fixed just by going over the code again or putting a breakpoint. So I never really explored the Debug Navigator. – R Menke Dec 24 '14 at 01:33
  • no worries, yeah it is an amazing feature, you can also browse through it with breakpoints if you want to double check that loops/selection structures are functioning correctly ect – nsij22 Dec 24 '14 at 02:33
2

That's what the Debug navigator is for. It shows the entire stack trace. And it is interactive: click a line of the call stack and you are taken to the line of code, at that level of the stack trace, where the problem is.

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141