objective-c @selector

1 What is @selector

c selector similar to the function pointers.

c function pointer:

int add(int val) {

return val + 1;

}

int (* c_func)(int val)

_func = add;

objective-c selector:

@interface foo

-(int)add:int val;

@end

 

SEL class_func;

class_func=@selector(add:int);

 

@selector method is to find the current class, and [@selector object (method name: Method parameter ..)]; Methods object corresponding to the corresponding class;

When looking for a class method, in addition to the method name, parameter also check one condition;

The method can be used to find the string variable name SEL = NSSelectorFromString (String method name);

Variables can be run with the SEL reverse isolated string method name: NSString * variable name = NSStringFromSelector (SEL parameter); 

 

2 selector What is the use

 

3 in your code How selector

After obtaining the appropriate values, how to deal with SEL value of it, it is still the same as function pointers, it is the implementation of
   
a function pointer execution, (there are a few equivalents

*c_func(10);

c_func(10);

SEL execution variables. PerformSelecor be performed using the method. 

[ Object the performSelector: the SEL variable withObject: Parameter. 1 withObject: parameter 2]

 

Guess you like

Origin www.cnblogs.com/hustdc/p/11621701.html