• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
self and super in objc
 

self and super in objc

on

  • 2,429 views

explain self and super in objc's class

explain self and super in objc's class

Statistics

Views

Total Views
2,429
Views on SlideShare
2,425
Embed Views
4

Actions

Likes
2
Downloads
24
Comments
0

1 Embed 4

http://twitter.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    self and super in objc self and super in objc Presentation Transcript

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