views:

77

answers:

2

Hi,

I want to call a method on an object which I get through [self delegate]. I know which class it is so I can import the class and call it normally but I could also use performSelector: which doesn't require importing my class. I do not need to pass a parameter to the method. And yes, I did read this. Which one is preferable in this case?

A: 

Generally speaking, reflective operations, such as performSelector:, are less efficient than the direct ones. I have to admit that I am not very familiar with objC, though.

Little Bobby Tables
A: 

Calling the method directly is more readable. performSelector: should be reserved for when you need higher order messaging.

Strictly speaking, you don't need to import the class to send it a message as message dispatch is dynamic rather than static, though you will get compile time warnings that the object may not respond to the selector.

outis
The benefit you get importing a class and sending it a message directly is compile time type/interface definition checking, and it is more efficient as stated by outis. performSelector is generally used for generic classes that cannot possibly know about the destination class, and rely soley on the programmer to insure that the method exists. i.e. UITimer, UIButton, etc.
Kenny