????Objective-C ??Self ?? Super ?????????????????? Objective-C ?е???????о?????????????????? self ?? super??????? oop ???????飬?? c++ ?????self ???? this??super ?????????????????????????????????????

?????? Objective-C ?е???????о?????????????????? ”self” ?? ”super”??????? oop ???????飬?? c++ ?????self ???? this??super ????????????????????????????????????????????????????

????@interface Person:NSObject { NSString* name; } - (void) setName:(NSString*) yourName; @end @interface PersonMe:Person { NSUInteger age; } - (void) setAge:(NSUInteger) age; - (void) setName:(NSString*) yourName andAge:(NSUInteger) age; @end @implementation PersonMe - (void) setName:(NSString*) yourName andAge:(NSUInteger) age { [self setAge:age]; [super setName:yourName]; } @end int main(int argc?? char* argv[]) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] PersonMe* me = [[PersonMe alloc] init]; [me setName:@"asdf" andAge:18]; [me release]; [pool drain]; return 0; }

?????????м???????????????PersonMe?е???????????е?setAge??????е?setName????Щ?????????????????????

???????????setName:andAge??????м??????У?

????NSLog(@"self ' class is %@"?? [self class]); NSLog(@"super' class is %@"?? [super class]);

??????????????????????????????class??????°??????????????????oop???????飬?????????????

????self ' s class is PersonMe super ' s class is Person

??????????????к?????????????

????self 's class is PersonMe super ' s class is PersonMe

????self ?? class ?????????????? super ?? class ??? PersonMe?

????????

????self ?????????????????????????÷????????????????????? _cmd?????????????? selector????????????? self??super ?????super ????????????????????????“??????????”?????? self ???????????????????????????????????????????? [self setName] ???? [super setName]??????“setName”???????????????? PersonMe* me ???????????????super ????????????????? setName ????????????????????????????????????

????????? self ???÷??????????????????б??п??????????У????????????;??????? super ??????????????б??п??????????????????????

????One more step

?????????????????????????????????????????????????????????????????? C ?????????????Apple ?? objcRuntimeRef ?????

????Sending Messages

????When it encounters a method invocation?? the compiler might generate a call to any of several functions to perform the actual message dispatch?? depending on the receiver?? the return value?? and the arguments. You can use these functions to dynamically invoke methods from your own plain C code?? or to use argument forms not permitted by NSObject’s perform… methods. These functions are declared in /usr/include/objc/objc-runtime.h.

????objc_msgSend sends a message with a simple return value to an instance of a class.

????objc_msgSend_stret sends a message with a data-structure return value to an instance of

????a class.

????objc_msgSendSuper sends a message with a simple return value to the superclass of an instance of a class.

????objc_msgSendSuper_stret sends a message with a data-structure return value to the superclass of an instance of a class.

??????????????????????? 4 ???????е?????????? _stret ??е????? _stret ??????????????????? objc_msgSend ?? objc_msgSendSuper ??????????????? [self setName] ???????????? objc_msgSend ???????????? objc_msgSend ????????壺

????id objc_msgSend(id theReceiver?? SEL theSelector?? ...)

????????????????????????????????????????????????? selector???????? selector ??????????????????????????????????? [self setName:] ??????????????滻????? objc_msgSend ?????????????? theReceiver ?? self??theSelector ?? @selector(setName:)????? selector ????? self ?? class ??????б?????? setName?????????????? selector ????????

??????????? [super setName] ???????????? objc_msgSendSuper ?????????? objc_msgSendSuper ????????壺

????id objc_msgSendSuper(struct objc_super *super?? SEL op?? ...)

????????????????objc_super????壬????????????????????????????selector???????objc_super?????????????????

????struct objc_super { id receiver; Class superClass; };

????????????????????????????????????? receiver????????????? objc_msgSend ?????????? receiver??????????????д super ?????????????????????????????????????????? PersonMe ?? setName:andAge ??????? [super setName:] ?????????????£?

???????? objc_super ????壬?????????????????????? receiver ?? PersonMe* me???? self ??????????????????? superClass ????? Person????? PersonMe ?????????? Person??