How to Debug 'Unrecognized Selector Sent to Instance' Error

How to debug unrecognized selector sent to instance

This error:

'NSInvalidArgumentException', reason: '-[Merchant merchantId]: unrecognized selector sent to instance 0x7fad19529490'.

Means that you have an object at location 0x7fad19529490 and you tried to call "merchantId" on it. That object does not respond to merchantId.

So, look very carefully at the definition of Merchant. Did you get the spelling of merchantId right in fieldMappings? Is it merchantID with a capital D?

If you are sure that merchant has a property named merchantId exactly, then, the next likely thing is that the object at 0x7fad19529490 is not a Merchant.

The easiest thing to do is to add an exception breakpoint (use the +) at the bottom of the breakpoint navigator. When this exception happens, grab the pointer address from the error (it might be different each time) and see what it is in the debugger. To do that, at the (lldb) prompt, type:

 po (NSObject*)(0x7fad19529490)

but use the address from the error. If it's a Merchant, I expect it to say something like:

<Merchant: 0x7fad19529490>

Or, if you have overridden description, it will be the output of that.

unrecognized selector sent to instance error in Objective-C

It looks like you're not memory managing the view controller properly and it is being deallocated at some point - which causes the numberButtonClicked: method to be sent to another object that is now occupying the memory that the view controller was previously occupying...

Make sure you're properly retaining/releasing your view controller.

[Label compare:]: unrecognized selector sent to instance

NSSortDescriptor(keyPath: \Sample.label, ascending: true) 

=>

NSSortDescriptor(keyPath: \Sample.label.name, ascending: true)

In the first one, you are trying to sort Sample on its label (Label) property.

So a some point, it will do [someLabelInstance compare:someOtherLabelInstance] to know if which one needs to be put before the other one. But, Label doesn't have an instance method compare(), that's why you get the error.

You want in fact sort on the name property of that label. Property which is a String (implicit by reading your code), and is "sortable" (implements compare()).

unrecognized selector sent to instance

I guess that you are incorrectly linking them.

you need to add UITableViewDelegate to your super Class

and in the viewDidLoad

self.tableView.delegate = self
self.tableView.dataSource = self

make sure you are linking the tableView as follows

IMG1. IMG2

you should have this!

You should end up with this



Related Topics



Leave a reply



Submit