-5

Here I can't understand what is selector?, still now I knew it is used for calling methods,and someother says its is a callback mechanism.

What is the difference between these two methods. Instance is created

Car *porsche = [[Car alloc] init];

The methods in these two ways whicih one is better.

SEL stepTwo = @selector(driveForDistance:);
[porsche performSelector:stepOne];

or

[porsche startEngine];
Cœur
  • 37,241
  • 25
  • 195
  • 267
dineshprasanna
  • 1,284
  • 4
  • 20
  • 37
  • Check this http://stackoverflow.com/q/2674827/2106973 – Navnath Godse May 24 '13 at 09:31
  • Check this This will clear your concept [here][1] [1]: http://stackoverflow.com/questions/11539479/what-is-use-of-performselector-in-ios –  May 24 '13 at 09:35
  • You may get answer for your question from this link http://stackoverflow.com/questions/5608476/whats-the-difference-between-a-method-and-a-selector – George May 24 '13 at 09:39

3 Answers3

2

"whicih one is better" - neithier (sic) one is better. They have different purposes.

Furthermore, there aren't "normal" (or "abnormal", for that matter) methods. There are methods. And selectors are unique names identifying methods.

If you don't need dynamic method dispatch, then there's no reason for using performSelector: (even less reason to use it the wrong way you used it - calling a method that takes one argument without any arguments). If you know which method you want to call on an object, just call it.

If you need reflection and dynamism, then it's useful and reasonable to use selectors to dynamically resolve methods.

0

Short Answer :

Main thing performSelector allows you to dynamically determine which selector to call a selector on the given object and there is not need to determine it Runtime. But as Both are some In Perfromselector a Selector is the name of a method. message is a selector and the arguments you are sending with it. and where method is a combination of a selector and an implementation. Try this there are number of Question on SO.

Buntylm
  • 7,345
  • 1
  • 31
  • 51
0

The performSelector allows you to dynamically determine which selector to call a selector on the given object. In other words the selector need not be determined before runtime.

Thus even though these are equivalent:

[theObject aMethod]; 
[theObject performSelector:@selector(theMethod)];

The second form allows you to do this:

SEL aSelector = findTheAppropriateSelectorForTheCurrentSituation();
[theObject performSelector: theSelector];
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66