The Most Insane and Unlikely Bug I Have Ever Encountered

I’m just thinking about the odds of this.  This is a one-in-a-million, horrible bug that cost me hours of debugging time.

I’m working on a <redacted> app;  You post content, it gets sent to a server, the recipient receives the content.  Both instances save a local copy of the content via CoreData.  The view is a Table View backed by a NSFetchedResultsController.  Easy.  Nothing complicated.

Symptom:  Both clients were only showing the contents of the first data model in the collection.  Any subsequent object’s contents was not being displayed.

This led me to believe that something must be going wrong with Core Data in some way… Do NSFetchedResultsControllers not update the table view if the changes occurred on the same context?  Do I have to reload the data?  Is it because of multi-threading?  Is there some sort of race condition?  Is it a result of merged Core Data NSManagedObjectModel objects? (I have another framework that uses Core Data) And so on.  I was going around and around in circles, getting nowhere.

Then, HOURS later, I noticed something in my table view.  The scroll indicator was small.  Like, really small.  What?!  I can scroll down??  There’s only one bit of content….

Then I looked into my helper methods for -tableView:heightForRowAtIndexPath:, and was horrified.  One helper was returning a calculated value plus a constant of 127348.  WTF?!  Yes, my cell heights were ~128000 points tall.  Of course I’m only going to see one object.

How could this happen?  Think of all the times you are using a window GUI and you think you are in one window, you type something, and you see nothing.  You must have had a different window open.  You click on the window you’re trying to type in, and carry on, thinking nothing of it.  This is what happened.  But think of the odds of that.  I was typing numbers in another window while the cursor was on a source file, right where numbers were accepted and wouldn’t cause compiler errors.  I unknowingly added 7328 to a constant of 12.  My cells just accidentally became 127348 tall.

These are the days where being the lone iOS developer suck.  I’m sure another guy would just come in and help you see what you’re missing.  I admit, so far on this project, everything that can go wrong, has gone wrong.  Mostly local server instances and VM’s, but still.  So unbelievably frustrating, even though it’s just a <redacted> app.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s