Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Objective-C Runtime

Avatar for Michał Michał
October 26, 2013

Objective-C Runtime

Mobilization 3 talk about Objective-C runtime

Avatar for Michał

Michał

October 26, 2013
Tweet

More Decks by Michał

Other Decks in Programming

Transcript

  1. ROADMAP 1. How does Objective-C work? 2. Categories and properties

    using runtime 3. JSON object mapping with runtime 4. Method swizzling
  2. Terminology 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! }! Class
  3. Terminology Selector A C string that represents given method name

    at runtime. Generated by the compiler and automatically mapped at runtime typedef struct objc_selector ! *SEL;!
  4. Messaging 1. Check for nil or ignored objects 2. Check

    cache for IMP method pointer 3. If it’s not there, check class dispatch table and continue up until found 4. If nothing is found, fallback to message forwarding
  5. Associated Objects Since OSX 10.6 runtime offers to associate objects

    with each other void objc_setAssociatedObject(id object, void *key, id value, objc_AssociationPolicy policy) id objc_getAssociatedObject(id object, void *key)