ݺߣ

ݺߣShare a Scribd company logo
Objective-C Runtime
DaidoujiChen 20150806
Review
2
Review
? ٵĻ?һ, ?һ message ?ߵ
doesNotRecognizeSelector: ^
ȵęC.
Review
1. + (BOOL)resolveInstanceMethod:(SEL)name;
2. - (id)forwardingTargetForSelector:(SEL)aSelector;
3. -
(NSMethodSignature*)methodSignatureForSelec
tor:(SEL)aSelector;
- (void)forwardInvocation:(NSInvocation
*)anInvocation;
Message
5
Message
׺ÿ?һA Objective-C e?涼
v, е Method \?{?, ҕ

[reciver message];
Message
reciver Ҫ\?@ Method  Object
message tҪ\?е Method name
ex: [normalObject invoke];
[NormalObject randomIntegerValue];
Message
Ȼ?, _Ҫ\?е reciver Ă
Object, compiler K֪, l
?,  Runtime ĕrŕQ.
Message
compiler ֻ Method D
[normalObject invoke];
to
objc_msgSend(normalObject, @selector(invoke));
Message
[NormalObject randomIntegerValue];
to
objc_msgSend([NormalObject class],
@selector(randomIntegerValue));
Message
P objc_msgSend ʲN, ?Wվ
@ӸV҂.
Message
1. It first finds the procedure (method
implementation) that the selector refers to. Since
the same method can be implemented differently
by separate classes, the precise procedure that it
finds depends on the class of the receiver.
Message
2. It then calls the procedure, passing it the
receiving object (a pointer to its data), along with
any arguments that were specified for the method.
Message
3. Finally, it passes on the return value of the
procedure as its own return value.
Message
Message
H, objc_msgSend ?Ϸׂ֞
Message
1. z reciver Ƿ nil
Message
2. z@ method  IMP Dzѽ
 class  cache
Message
3. , t?һֱϲ.
Message
Q&A
Reference
Objective-C Runtime Programming Guide
A Look Under the Hood of objc_msgSend()
Chapter 4 Assembly Language

More Related Content

Objective c runtime 2