performSelector throwing invalid argument, why?

156 views Asked by At

This line of code works perfectly

[self explodeBomb:obj];

but if I replace it with the following line, I get an NSInvalidArgument Exception, with the reason being an unrecognized selector.

 [self performSelector:@selector(explodeBomb) withObject:obj ];

The definition of the method is as follows:

 -(void)explodeBomb:(SKNode *)bomb

I know, this has to be me not understanding something fundamental. But why I am able to call the method directly with no problems, but when I try to use the performSelector it blows up? For the record obj is defined as an ID. I tried changing the signature of explodeBomb to take an ID and then explicitly cast it inside the method, but that threw the same exception. Anyone know what the heck I am doing wrong?

1

There are 1 answers

2
san On BEST ANSWER

Use : and write like below

 [self performSelector:@selector(explodeBomb:) withObject:obj ];

Since your method explodeBomb has an argument so you have to specify :