Your SlideShare is downloading. ×
0
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
self and super in objc
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

self and super in objc

2,260

Published on

explain self and super in objc's class

explain self and super in objc's class

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,260
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Obj-C self super twitter:@vonbo
  • 2. self class is Derivedsuper class is Derived
  • 3. obj-c• [self class] or [super class]• self• super “ ” self super class
  • 4. 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.
  • 5. 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.
  • 6. objc_msgSend• • id objc_msgSend(id theReceiver, SEL theSelector, ...)• [self class] • theReceiver -> self • SEL -> class
  • 7. objc_msgSendSuper• • id objc_msgSendSuper(struct objc_super *super, SEL op, ...)• [super class] • objc_super -> some struct? • SEL -> class
  • 8. objc_superstruct objc_super { id receiver; Class superClass;}
  • 9. objc_msgSendSuper• [super class] • objc_super receiver = self superClass = Base • objc_msgSendSuper objc_super -> superClass selector • selector objc_super -> receiver
  • 10. 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
  • 11. 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
  • 12. How to get super class’s name?• [self superclass]• NSLog(@"super class is %@", [self superclass]);• The output is “Base” !
  • 13. The End

×