Objective-C performSelector does not call a method with a parameter

I have a problem with performSelector. It works if I call a method without parameters, but it doesn't even call a method if I pass a parameter.

Example:

- (void)test
{
 NSLog(@"test"); //it works!!
}    
...
[self performSelector:@selector(test) withObject:nil afterDelay:1.0];


- (void)switchOn:(NSNumber *) index
{
 NSLog(@"switchOn"); //it doesn't work :-(
}   
....
NSLog(@"int is %d", [((NSNumber *)obj) intValue]); //print the correct value
[self performSelector:@selector(switchOn:) withObject:obj afterDelay:1.0];

I also do not get errors. Where can this be a problem?

thank

+3
source share
3 answers

What is the type of switchOn parameter: selector?

It must have a type identifier, otherwise executed. Selector: WithObject: does not work. To quote documents:

aSelector , . NSInvocation.

+3

performSelectorWithObject: , . id. - NSInvocation.

, .

+2

:

- (void)switchOn:(id)index
0

Source: https://habr.com/ru/post/1750897/


All Articles