#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