views:

41

answers:

2

I want that something like this:

[myObject selectorNotDefined];

will cause a warning. Is there an option to make this happen?

To be more specific, when I add this code to my existing project:

NSObject *myObject = [[NSObject alloc] init];
[myObject selectorNotDefined];

The compiler will not invoke any warning.

If I create a new project and add these lines it invokes a warning.

What's wrong with my existing project?

A: 

It depends on what type you have assigned myObject. If it's an id type, you won't get any warnings, but if you make it a specific object type, the compiler will check to see of the method is declared in the header files.

lucius
bbum
+1  A: 

If you write:

NSObject *myObject = [[NSObject alloc] init];
[myObject selectorNotDefined];

You will definitely get a warning: myObject might not respond to selector selectorNotDefined

Or you can check: i

f([myObject respondsTo:selector(selectorNotDefined)]{
 [myObject selectorNotDefined]; //or
[myObject performSelector:(selectorNotDefined) withObject:nil afterDelay:0];

}
nacho4d