Never Lose Your Error Messages Again

Tell me if this has happened to you.

You're diligently finishing a feature (and damn is it a great feature).  And you go to run the simulator, things are looking great and then BOOM.  Simulator crashes, error registers to the console, and your day is ruined.

Well not really, right? Because at least you have an error statement. Oh, and it's a simple one.  "Array index out of bounds".  Cool, glad we decided to check for those with guards.

You search the code base and there are exactly 5 different places that error shows up in the code base. D'oh!  Well at least it's narrowed down your code search from 30,000 lines to 5.  But we can do better than that right? 

Maybe we could just write the class name at the beginning of our errors.  That would make it easier to find at least.  Well what happens when the class name changes?  Huh.

Never fear, simple swift feature is here!  You can quickly print the name of the class in all your error messages with the following snippet:

print("\(type(of:self)): Array index out of bounds")

If you haven't had a chance to use Type(of:), go ahead and give it a whirl.  And never guess where a print statement comes from again.

What's your favorite way to track down error messages?