TIL: debugging 'unrecognized selector sent to instance'

Whenever I see unrecognized selector sent to instance I think to myself, wow, this is the least helpful and most vague description I’ve ever seen. But alas, we must work with what we got. So, the two most common culprits of this all-too-often error message is:

  • there is something wrong with the connection between my storyboard and the associated ViewController. Often a typo/I changed a name in one place and not the other ;)
  • something has been deallocated, but there is still something calling a method on this no longer existing view controller. Perhaps in the routing logic, where a segue is implemented programmatically before all the data needed in the destination view controller has been set.

But today, I discovered another culprit!

I was getting this error during the assembly code following a request to the server, which led me to realize that it was perhaps a problem with the way the data coming from the server was formatted.

And huzzah!

Our JSONDictionary serializer was expecting a dictionary, however the response from the server was an array!

More helpful tips here.

Another mystery solved.