All Xcode knows is that there is no class, either in the system code or in your program, that declares a selector called addobject
. You can prove this by creating a custom class that declares an addobject
method, and the warning should go away, but of course the program will crash with a unrecognized selector sent to object
error message.
How XCode knows about name of function at compile time?
-
08-07-2023 - |
Pregunta
I have written simple code to practice selector
in Objective C, which is working fine
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"A",@"B", nil];
NSLog(@"Before adding %@",array);
SEL message = @selector(addObject:); //I will change this line
if([array respondsToSelector:message])
{
[array performSelector:message withObject:@"C"];
}
NSLog(@"After adding %@",array);
But as soon as I change selector line to,
SEL message = @selector(addobject:);// Just changed name of selector
XCode starts giving warning :
Undeclared selector 'addobject:'
Now, question is how XCode knows at compile time about name of method is correct or not. Is there always list of selector generates internally for whatever object I am creating? In this case for NSMutableArray
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow