0

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?

Andrey
  • 6,526
  • 3
  • 39
  • 58
Speckpgh
  • 3,332
  • 1
  • 28
  • 46

1 Answers1

3

Use : and write like below

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

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

san
  • 3,350
  • 1
  • 28
  • 40
  • Though I would think the fact with object isn't nil would take care of that, but lesson learned, thanks. – Speckpgh Jan 09 '14 at 07:54
  • Yes, +1 on comment. And due to this autocomplete, sometimes people tend to forget exact thing. As far as I feel this way. ;) – san Jan 09 '14 at 11:18