skip to Main Content

I’m investigating real user issues through Crashes report in Xcode Organizer.

enter image description here

Xcode tells the error line but don’t give any information which value exactly caused the exception. There are many candidates to investigate.
I think it is not difficult work for Xcode to let me know which value caused the exception.

So.. I wonder is it possible to know which value exactly caused the nil exception from the crashes report?

2

Answers


  1. I think best approach and main approach for hunting the nil value is :

    breakpoints in debug mode. So you can put breakpoints your specific lines and catch the nil value just before.

    Login or Signup to reply.
  2. Instead of blaming Xcode, write better code. Your exclamation points are the possible sites of these crashes. So eliminate them. There should be no exclamation points in your code. They mean "please crash me", so you can hardly complain when the runtime does just what you asked it to do.

    For instance, as an example, where you say standardDate!, instead, ask yourself: if standardDate is nil, we will crash, so what would be an acceptable substitute in that case?

    • If your answer is that there is no acceptable substitute, as it should never be nil, then the crash is good, as you are being alerted to a bug elsewhere in the program. Go off and figure out what that bug is.

    • If there is an acceptable substitute in that case, such as the empty string, then use it here, e.g. standardDate ?? "". In this way, eliminate all uses of exclamation points in your app.

    There are a few well-documented situations where an exclamation point is pretty much inevitable and cannot be eliminated, such as an @IBOutlet declaration or a cell subclass downcast, but otherwise there should be no exclamation marks in your code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search