5. obj-c
• [self class] or [super class]
• self
• super “ ” self
super
class
6. C -1
• 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.
7. C -2
• 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.uperclass of an instance of a
class.
8. objc_msgSend
•
• id objc_msgSend(id theReceiver, SEL
theSelector, ...)
• [self class]
• theReceiver -> self
• SEL -> class
9. objc_msgSendSuper
•
• id objc_msgSendSuper(struct objc_super
*super, SEL op, ...)
• [super class]
• objc_super -> some struct?
• SEL -> class
12. That is ...
• [self class]
• objc_msgSend(receiver, class)
• receiver = Derived, “class” selector is from
NSObject
• [super class]
• objc_msgSendSuper(objc_super, class)
• ==> objc_msgSend(objc_super -> receiver, class)
• receiver = Derived, “class” selector is from
NSObject
• NSObject class receiver class
13. That is ...
• [self class]
• objc_msgSend(receiver, class)
• receiver = Derived, class method is from NSObject
• [super class]
• objc_msgSendSuper(objc_super, class)
So ...
• [self class] ‘s output is Derived
==> objc_msgSend(objc_super -> receiver,
class) class] ‘s output is Derived too !
[super
• receiver = Derived, class method from NSObject
• NSObject class receiver class
14. How to get super
class’s name?
• [self superclass]
• NSLog(@"super class is %@", [self
superclass]);
• The output is “Base” !