SlideShare a Scribd company logo
Obj-C   self       super
               twitter:@vonbo
self and super in objc
self and super in objc
self class is Derived
super 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_super

struct 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

More Related Content

PDF
Qcon beijing 2010
PDF
Beginning to iPhone development
PDF
Http Live Streaming Intro
PPTX
Http live streaming technical presentation
PDF
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
PDF
HTTP Live Streaming
PPTX
Objective-c Runtime
Qcon beijing 2010
Beginning to iPhone development
Http Live Streaming Intro
Http live streaming technical presentation
Mobile Movies with HTTP Live Streaming (CocoaConf DC, March 2013)
HTTP Live Streaming
Objective-c Runtime

Similar to self and super in objc (20)

PDF
What Makes Objective C Dynamic?
PDF
Pavel kravchenko obj c runtime
PPTX
Objective-c for Java Developers
PPT
iOS Application Development
PPTX
Presentation 3rd
PPTX
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
PPT
Objective-C for iOS Application Development
PDF
Bootstrapping iPhone Development
PDF
Никита Корчагин - Programming Apple iOS with Objective-C
PPT
Objective c intro (1)
PDF
201005 accelerometer and core Location
KEY
Runtime
PDF
Objective c runtime
PPTX
Introduction to Objective - C
PDF
Introduction to objective c
PDF
Programming with Objective-C
PDF
Objective-C A Beginner's Dive (with notes)
PDF
Intro to iOS Development • Made by Many
PPTX
Presentation 1st
PDF
iOS Programming Intro
What Makes Objective C Dynamic?
Pavel kravchenko obj c runtime
Objective-c for Java Developers
iOS Application Development
Presentation 3rd
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective-C for iOS Application Development
Bootstrapping iPhone Development
Никита Корчагин - Programming Apple iOS with Objective-C
Objective c intro (1)
201005 accelerometer and core Location
Runtime
Objective c runtime
Introduction to Objective - C
Introduction to objective c
Programming with Objective-C
Objective-C A Beginner's Dive (with notes)
Intro to iOS Development • Made by Many
Presentation 1st
iOS Programming Intro
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Ad

self and super in objc

  • 1. Obj-C self super twitter:@vonbo
  • 4. self class is Derived super class is Derived
  • 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
  • 10. objc_super struct objc_super { id receiver; Class superClass; }
  • 11. objc_msgSendSuper • [super class] • objc_super receiver = self superClass = Base • objc_msgSendSuper objc_super -> superClass selector • selector objc_super -> receiver
  • 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” !