Classes (class type) in OBJC (objective-c), Selector (selector sel), function pointer (IMP) I saw a cow in the garden today "OBJECTIVE-C 2.0 with Cocoa Foundation--- The 5,class type, selector selector, and function pointer are very exciting, and can not help but annotate its code with annotations for later viewing. Personal experience: The "class type variable" in OBJ-C is more flexible than the object base class in C #, and it can be used to generate any type of instance (but it is not nsobject). and the selector sel and the function pointer imp, if you want to have a relationship with C #, these two combine, on the point similar to the Reflection + delegate in C #, you can invoke the method directly according to a method name string. "OX" base class Cattle.h View source print?
1 |
#import <Foundation/Foundation.h> |
3 |
@interface Cattle: nsobject { |
7 |
-(void) Setlegscount: (int) count; |
CATTLE.M View Source print?
03 |
@implementation Cattle |
07 |
NSLog (@ "Hello, I am a cattle, I have%d legs.", legscount); |
10 |
-(void) Setlegscount: (int) count |
Subclass "Bull" Bull.h View source print?
01 |
#import <Foundation/Foundation.h> |
04 |
@interface Bull:cattle { |
08 |
-(nsstring*) Getskincolor; |
09 |
-(void) Setskincolor: (nsstring *) color; |
BULL.M View Source print?
08 |
NSLog (@ "Hello, I am a%@ bull, I have%d legs.", [self getskincolor],legscount); |
11 |
-(nsstring*) getskincolor |
16 |
-(void) Setskincolor: (nsstring *) color |
Proxy class DoProxy.h (here's the key code) View source print?
01 |
#import <Foundation/Foundation.h> |
03 |
Defining several string constants |
04 |
#define Set_skin_color @ "Setskincolor:" |
05 |
#define BULL_CLASS @ "BULL" |
06 |
#define CATTLE_CLASS @ "cattle" |
09 |
@interface Doproxy: nsobject { |
17 |
Define a function pointer (traditional C language processing method) |
18 |
void (*SETSKINCOLOR_FUNC) (ID,SEL,nsstring*); |
20 |
A function pointer that defines an IMP method (the recommended way in obj-c) |