How do I fix unrecognized selector sent to instance?

How do I fix unrecognized selector sent to instance?

Fixing «Unrecognized Selector Sent To Instance»

  1. First, check that the selector is called on the right object. The function name should exist on that object.
  2. Then, check the function name.
  3. Then, check the function parameters.

What does unrecognized selector sent to instance mean?

It means that you have called a method on an object which does not support that method. The reason it says ‘unrecognised selector’ is that method invocation is implemented by a message sending mechanism. The part of the message that contains the method name is called the selector.

What is a selector in Objective-C?

In Objective-C, selector has two meanings. It can be used to refer simply to the name of a method when it’s used in a source-code message to an object. It also, though, refers to the unique identifier that replaces the name when the source code is compiled. Compiled selectors are of type SEL .

What is Nsexception?

An object that represents a special condition that interrupts the normal flow of program execution.

What to do when you see unrecognized selector sent to instance?

Next time if you see an error message: “unrecognized selector sent to instance”, start debugging by investigating objects with the type ID. It’s possible that the class of the offending object is not what you think it is at runtime. Therefore try to use introspection to check if the object responds to the selector in question.

Why is unrecognized selector sent to instance in Swift?

The Swift compiler can’t check whether the function actually exists before you run your app, so if you’ve written the selector incorrectly, you’ll get that Unrecognized selector sent to instance. If Swift could have checked whether the selector exists when compiling the app, it would have shown you the Use of unresolved identifier error.

What does unrecognized selector sent to instance mean in Xcode?

One of the most common errors in Xcode is “ Unrecognized Selector Sent To Instance “. Today I will try to explain the reason why we get this error and most importantly how to fix it. But before we start investigating the code, we should better understand the error message in the console area.

About the Author

You may also like these