iOS develops a simple summary of SEL

Source: Internet
Author: User

#import <Foundation/Foundation.h>@interface person:nsobject-(void) test1; -(void) Test2: (NSString *) str; @end
" Person.h " @implementationPerson-(void) test1{    NSLog (@ " parameterless object method " );} -(void) Test2: (NSString *) str{    NSLog (@ " method%@ with parameters" , str); } @end
#import <Foundation/Foundation.h>#import"Person.h"intMainintargcConst Char*argv[]) {@autoreleasepool { person*p=[[Person alloc] init];                        [P test1];                [P Performselector: @selector (test1)]; [P Performselector: @selector (test2:) Withobject:@"Hello"]; }    return 0;}

SEL is a wrapper for the method. Package SEL type data it corresponds to the corresponding method address, find the method address to call the method

1. Where to store the method

    • The methods of each class in memory are stored in the class object
    • Each method has a corresponding SEL type of data
    • The corresponding method address can be found based on a SEL data, which in turn calls the method
    • Definition of SEL type: typedef struct OBJC_SELECTOR *sel

Creation of 2.SEL objects

SEL s2 = nsselectorfromstring (@ "test1"// 

iOS develops a simple summary of 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.