SEL data types, @selector usage, and calling SEL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.