SlideShare a Scribd company logo
1 of 19
Download to read offline
Objective-C Runtime


                           dong.linlan@gmail.com


Sunday, October 30, 2011
History
     Brad Cox, Tom Love, 1981, ITT Corp.

     Reusability & Backward Compatibility with C

     Smalltalk + C = Object-Oriented Pre-Compiler

     Objective-C, StepStone

     1988, NeXT, AppKit & Foundation Kit


Sunday, October 30, 2011
What is an Object ?
                           @interface NSObject <NSObject> {
                               Class isa;
                           }

                           struct NSObject {
                               Class isa;
                           }




Sunday, October 30, 2011
What is an Object ?
                           @interface MyName : NSObject {
                             NSString *firstName;
                             NSString *lastName;
                           }

                           struct MyName {
                             Class     isa;
                             NSString *firstName;
                             NSString *lastName;
                           }


Sunday, October 30, 2011
What is an Object ?
                           NSObject      NSObject
                           0  isa        0  isa
                                         4   foobar
                             MyName
                           0     isa        MyName
                           4 firstName    0      isa
                           8 lastName    4 firstName
                                               foobar
                                         8 firstName
                                             lastName
                                         12 lastName
Sunday, October 30, 2011
/usr/include/objc/runtime.h
  typedef struct objc_class *Class;

  struct objc_class {
      Class isa;

  #if !__OBJC2__
      Class super_class                       OBJC2_UNAVAILABLE;
      const char *name                        OBJC2_UNAVAILABLE;
      long version                            OBJC2_UNAVAILABLE;
      long info                               OBJC2_UNAVAILABLE;
      long instance_size                      OBJC2_UNAVAILABLE;
      struct objc_ivar_list *ivars            OBJC2_UNAVAILABLE;
      struct objc_method_list **methodLists   OBJC2_UNAVAILABLE;
      struct objc_cache *cache                OBJC2_UNAVAILABLE;
      struct objc_protocol_list *protocols    OBJC2_UNAVAILABLE;
  #endif

  } OBJC2_UNAVAILABLE;

Sunday, October 30, 2011
isa
                                 super            super
                                                            NSObject      isa
                                                            (MetaClass)

                                                      isa
       Object Model                NSObject                        super
                                       (Class)



                                 super
                                                            MyName
                                                            (MetaClass)
                                                      isa
                                       MyName
                                        (Class)

                  MyName         isa
                    (instance)


Sunday, October 30, 2011
isa-swizzling
                           HerName      MyName *myName = [MyName alloc] init];
                            (Class)
                                        myName->isa = [HerName class];



                                isa
                                                MyName
                                                 (Class)

                           MyName         isa
                           (instance)




Sunday, October 30, 2011
isa-swizzling
             Key-Value Observing

             NSZombie

             State Machine

               ......




Sunday, October 30, 2011
Where the Objects Come From
                               <<Squeak, Open Personal Computing and Multimedia>>

        Object is a metaphor of cell.

        The complexity is handled through each object performing its
        own functions, without undue interference from others.

        The robustness comes from the fact that the loss of an
        object does not damage other objects.

         Supporting growth comes from using the same structuring and
         communication mechanism throughout.

         Finally, the reuse comes from each object performing its own
         role, with only minimal connections to other objects.

Sunday, October 30, 2011
Messaging
      Smalltalk is not only NOT its syntax or the class
      library, it is not even about classes.

      I'm sorry that I long ago coined the term "objects"
      for this topic because it gets many people to focus
      on the lesser idea.

      The big idea is "messaging".

                                            ---- Alan Kay

Sunday, October 30, 2011
Messaging
     Selector
                           typedef struct objc_selector   *SEL;
     IMP
                           typedef id (*IMP)(id, SEL, ...);

      id
                           typedef struct objc_object {
                                Class isa;
                           } *id;

Sunday, October 30, 2011
Messaging
                           @implementation   MyName

                           - (void)printName:(NSString *)name
                           {
                              ......
                           }

                           @end


     void - [MyName printName:](id self, SEL _cmd, NSString *name)
     {
       ......
     }

Sunday, October 30, 2011
Messaging
                           [name printName:@”lldong”];




      objc_msgSend(name, @selector(printName:), @”lldong”);




Sunday, October 30, 2011
Messaging
                     IMP class_getMethodImplementation(Class cls, SEL name);

                     - (IMP) methodForSelector:(SEL)sel;




     id objc_msgSend(id receiver, SEL name, arguments...)
     {
         IMP function = Class_getMethodImplementation(receiver->isa, name);
         return function(arguments);
     }




Sunday, October 30, 2011
isa
                                 super            super
                                                            NSObject      isa
                                                            (MetaClass)

                                                      isa
                                   NSObject                        super
                                       (Class)



                                 super
                                                            MyName
                                                            (MetaClass)
                                                      isa
                                       MyName
                                        (Class)

                  MyName         isa
                    (instance)


Sunday, October 30, 2011
Messaging
                           + (BOOL)resolveInstanceMethod:(SEL)sel
        1                  + (BOOL)resolveClassMethod:(SEL)sel


        2                  - (id)forwardingTargetForSelector:(SEL)sel


        3 - (void)forwardInvocation:(NSInvocation *)invocation




Sunday, October 30, 2011
Conclusion

                            NO MAGIC




Sunday, October 30, 2011
Q&A


    allContents



Sunday, October 30, 2011

More Related Content

What's hot

Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
Defining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesDefining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesCtOlaf
 

What's hot (7)

Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Defining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesDefining classes-part-i-constructors-properties
Defining classes-part-i-constructors-properties
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
Chapter iii(oop)
Chapter iii(oop)Chapter iii(oop)
Chapter iii(oop)
 
Java
JavaJava
Java
 

Viewers also liked

06module 16 building-lan
06module 16 building-lan06module 16 building-lan
06module 16 building-lansetioaribowo
 
ไม้ตะกู
ไม้ตะกูไม้ตะกู
ไม้ตะกูchokchai57
 
Saludos en español a
Saludos en español aSaludos en español a
Saludos en español asalpadilla
 
คู่มือการนิเทศ
คู่มือการนิเทศคู่มือการนิเทศ
คู่มือการนิเทศKrueed Huaybong
 
Introdução às Metodologias Ágeis de Desenvolvimento
Introdução às Metodologias Ágeis de DesenvolvimentoIntrodução às Metodologias Ágeis de Desenvolvimento
Introdução às Metodologias Ágeis de DesenvolvimentoJerry Medeiros
 
Circuitos Digitales - Corrimiento de bits
Circuitos Digitales - Corrimiento de bits Circuitos Digitales - Corrimiento de bits
Circuitos Digitales - Corrimiento de bits Fernando Marcos Marcos
 
2б космос
2б космос2б космос
2б космосZoyaSGT
 
24 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps333524 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps3335O ÚLTIMO CHAMADO
 
Arquitetura de Informação - Personas e Cenários
Arquitetura de Informação - Personas e CenáriosArquitetura de Informação - Personas e Cenários
Arquitetura de Informação - Personas e Cenáriosposgraduacaorj
 
FIGURAS GEOMETRICAS
FIGURAS GEOMETRICASFIGURAS GEOMETRICAS
FIGURAS GEOMETRICASsaraycreek
 
งานโลหะแผ่น5 2
งานโลหะแผ่น5 2งานโลหะแผ่น5 2
งานโลหะแผ่น5 2Pannathat Champakul
 
презентация
презентацияпрезентация
презентацияmetodkopilka
 
Iñigo Aranguren, eguberrietako postala
Iñigo Aranguren, eguberrietako postalaIñigo Aranguren, eguberrietako postala
Iñigo Aranguren, eguberrietako postalaaskain2
 
Informativo de janeiro
Informativo de janeiroInformativo de janeiro
Informativo de janeiroLua Barros
 

Viewers also liked (20)

RECTAS PARALELAS Y PERPENDICULARES
RECTAS PARALELAS Y PERPENDICULARESRECTAS PARALELAS Y PERPENDICULARES
RECTAS PARALELAS Y PERPENDICULARES
 
06module 16 building-lan
06module 16 building-lan06module 16 building-lan
06module 16 building-lan
 
ไม้ตะกู
ไม้ตะกูไม้ตะกู
ไม้ตะกู
 
Carta pelas aguas
Carta pelas aguasCarta pelas aguas
Carta pelas aguas
 
Saludos en español a
Saludos en español aSaludos en español a
Saludos en español a
 
คู่มือการนิเทศ
คู่มือการนิเทศคู่มือการนิเทศ
คู่มือการนิเทศ
 
Introdução às Metodologias Ágeis de Desenvolvimento
Introdução às Metodologias Ágeis de DesenvolvimentoIntrodução às Metodologias Ágeis de Desenvolvimento
Introdução às Metodologias Ágeis de Desenvolvimento
 
Circuitos Digitales - Corrimiento de bits
Circuitos Digitales - Corrimiento de bits Circuitos Digitales - Corrimiento de bits
Circuitos Digitales - Corrimiento de bits
 
2б космос
2б космос2б космос
2б космос
 
24 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps333524 as-3-mensagens-angelicaspps3335
24 as-3-mensagens-angelicaspps3335
 
Jamie's resume
Jamie's resumeJamie's resume
Jamie's resume
 
Mfhp12 c excel_4ed_solucoes
Mfhp12 c excel_4ed_solucoesMfhp12 c excel_4ed_solucoes
Mfhp12 c excel_4ed_solucoes
 
Arquitetura de Informação - Personas e Cenários
Arquitetura de Informação - Personas e CenáriosArquitetura de Informação - Personas e Cenários
Arquitetura de Informação - Personas e Cenários
 
FIGURAS GEOMETRICAS
FIGURAS GEOMETRICASFIGURAS GEOMETRICAS
FIGURAS GEOMETRICAS
 
Inatel beja
Inatel bejaInatel beja
Inatel beja
 
งานโลหะแผ่น5 2
งานโลหะแผ่น5 2งานโลหะแผ่น5 2
งานโลหะแผ่น5 2
 
презентация
презентацияпрезентация
презентация
 
Redes Sociais Corporativas e engajamento do público interno
Redes Sociais Corporativas e engajamento do público internoRedes Sociais Corporativas e engajamento do público interno
Redes Sociais Corporativas e engajamento do público interno
 
Iñigo Aranguren, eguberrietako postala
Iñigo Aranguren, eguberrietako postalaIñigo Aranguren, eguberrietako postala
Iñigo Aranguren, eguberrietako postala
 
Informativo de janeiro
Informativo de janeiroInformativo de janeiro
Informativo de janeiro
 

Similar to Objective runtime

Similar to Objective runtime (10)

«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
Metaclasses – Python’s Object-Oriented Paradigm and Its Metaprogramming
Metaclasses – Python’s Object-Oriented Paradigm and Its MetaprogrammingMetaclasses – Python’s Object-Oriented Paradigm and Its Metaprogramming
Metaclasses – Python’s Object-Oriented Paradigm and Its Metaprogramming
 
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
 
Lecture 03
Lecture 03Lecture 03
Lecture 03
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 
About Python
About PythonAbout Python
About Python
 
The messy lecture
The messy lectureThe messy lecture
The messy lecture
 
Oop07 6
Oop07 6Oop07 6
Oop07 6
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Objective runtime

  • 1. Objective-C Runtime dong.linlan@gmail.com Sunday, October 30, 2011
  • 2. History Brad Cox, Tom Love, 1981, ITT Corp. Reusability & Backward Compatibility with C Smalltalk + C = Object-Oriented Pre-Compiler Objective-C, StepStone 1988, NeXT, AppKit & Foundation Kit Sunday, October 30, 2011
  • 3. What is an Object ? @interface NSObject <NSObject> { Class isa; } struct NSObject { Class isa; } Sunday, October 30, 2011
  • 4. What is an Object ? @interface MyName : NSObject { NSString *firstName; NSString *lastName; } struct MyName { Class isa; NSString *firstName; NSString *lastName; } Sunday, October 30, 2011
  • 5. What is an Object ? NSObject NSObject 0 isa 0 isa 4 foobar MyName 0 isa MyName 4 firstName 0 isa 8 lastName 4 firstName foobar 8 firstName lastName 12 lastName Sunday, October 30, 2011
  • 6. /usr/include/objc/runtime.h typedef struct objc_class *Class; struct objc_class { Class isa; #if !__OBJC2__ Class super_class OBJC2_UNAVAILABLE; const char *name OBJC2_UNAVAILABLE; long version OBJC2_UNAVAILABLE; long info OBJC2_UNAVAILABLE; long instance_size OBJC2_UNAVAILABLE; struct objc_ivar_list *ivars OBJC2_UNAVAILABLE; struct objc_method_list **methodLists OBJC2_UNAVAILABLE; struct objc_cache *cache OBJC2_UNAVAILABLE; struct objc_protocol_list *protocols OBJC2_UNAVAILABLE; #endif } OBJC2_UNAVAILABLE; Sunday, October 30, 2011
  • 7. isa super super NSObject isa (MetaClass) isa Object Model NSObject super (Class) super MyName (MetaClass) isa MyName (Class) MyName isa (instance) Sunday, October 30, 2011
  • 8. isa-swizzling HerName MyName *myName = [MyName alloc] init]; (Class) myName->isa = [HerName class]; isa MyName (Class) MyName isa (instance) Sunday, October 30, 2011
  • 9. isa-swizzling Key-Value Observing NSZombie State Machine ...... Sunday, October 30, 2011
  • 10. Where the Objects Come From <<Squeak, Open Personal Computing and Multimedia>> Object is a metaphor of cell. The complexity is handled through each object performing its own functions, without undue interference from others. The robustness comes from the fact that the loss of an object does not damage other objects. Supporting growth comes from using the same structuring and communication mechanism throughout. Finally, the reuse comes from each object performing its own role, with only minimal connections to other objects. Sunday, October 30, 2011
  • 11. Messaging Smalltalk is not only NOT its syntax or the class library, it is not even about classes. I'm sorry that I long ago coined the term "objects" for this topic because it gets many people to focus on the lesser idea. The big idea is "messaging". ---- Alan Kay Sunday, October 30, 2011
  • 12. Messaging Selector typedef struct objc_selector *SEL; IMP typedef id (*IMP)(id, SEL, ...); id typedef struct objc_object { Class isa; } *id; Sunday, October 30, 2011
  • 13. Messaging @implementation MyName - (void)printName:(NSString *)name { ...... } @end void - [MyName printName:](id self, SEL _cmd, NSString *name) { ...... } Sunday, October 30, 2011
  • 14. Messaging [name printName:@”lldong”]; objc_msgSend(name, @selector(printName:), @”lldong”); Sunday, October 30, 2011
  • 15. Messaging IMP class_getMethodImplementation(Class cls, SEL name); - (IMP) methodForSelector:(SEL)sel; id objc_msgSend(id receiver, SEL name, arguments...) { IMP function = Class_getMethodImplementation(receiver->isa, name); return function(arguments); } Sunday, October 30, 2011
  • 16. isa super super NSObject isa (MetaClass) isa NSObject super (Class) super MyName (MetaClass) isa MyName (Class) MyName isa (instance) Sunday, October 30, 2011
  • 17. Messaging + (BOOL)resolveInstanceMethod:(SEL)sel 1 + (BOOL)resolveClassMethod:(SEL)sel 2 - (id)forwardingTargetForSelector:(SEL)sel 3 - (void)forwardInvocation:(NSInvocation *)invocation Sunday, October 30, 2011
  • 18. Conclusion NO MAGIC Sunday, October 30, 2011
  • 19. Q&A allContents Sunday, October 30, 2011