1.SEL Data types
The SEL is a pointer-type data, similar to a function pointer in the C language. In OC, each object method has a SEL variable corresponding to it. When we call the object method, the compiler converts the method into a SEL data and then goes to the class to find the SEL for the method. (The deep principles involved here do not delve into this article, only the use of SEL and @selector)
[e-mail protected] Usage
@selector (method name), which returns data for an SEL type, so it can be used. Suppose that there is an object method in the person class called run (). And we can call it this way:
1 SEL f1 = @selector (run); 2 3 person* Tom = [[Person alloc] init]; 4 5 // call the Run method
3. Call the SEL
Each method has its own SEL variable into _cmd, which is called inside the method, and can be printed out by the method name. Here's how:
-(void) test{ NSLog ("%@"// print out: Test }
The principle is to call Nsstringfromselector to convert the _cmd into a string and then print. Performselector also has a version of the incoming parameters, refer to the OC documentation in Xcode for details.
Summary: SEL is a data type that calls @selector () to convert any data into SEL data, and calls the Performselector family of object methods to invoke the SEL corresponding method.
SEL data types, @selector usage, and calling SEL