Self-study iOS development-------objective-c Dynamic Call method notes

Source: Internet
Author: User

OC Dynamic Call
The function call of OC is the message sending pattern, that is, when the function is called dynamically at runtime, OC can call any function at compile time, so long as the function is declared, it will not error, and when actually running
The corresponding function is found based on the name of the function to invoke the
[Asperson SayHello]

At compile time, the runtime will convert the above code to
Objc_msgsend (Asperson @selector (SayHello))

All defined types inherit from a pointer to class that exists in Nsobject,nsobject

Class is a function pointer to the OBJC_CLASS structure;

structconst Charchar *longlonglong  struct objc_ivar_list *struct objc_method_list **struct Objc_cache *struct objc_protocol_list *protocols;}

The class Isa:obj object contains an Isa, which points to the generic class, which contains general variables and object methods,
ISA in the general class points to metaclass, which stores static object (static) members and class methods in a static class.

Class Super_class: Points to the parent class, or null if the class is a root class

Figure

Isa in Metaclass points to root metaclass instead of Super Metaclass
Root Metaclass inherits the root class, and root metaclass points to its own


const CHAR *name: Class name

Long version: The release information for the class, which defaults to 0

Long info: Some bit identifiers for the run time, such as Cls_class (0x1l), indicate that the class is a normal class, which contains object methods and member variables; Cls_meta (0x2l) indicates that the class is Metaclass, which contains class methods;

Long instance_size: the instance variable size of the class (including instance variables inherited from the parent class);

struct objc_ivar_list *ivars: Pointer to member variable struct body structint  ivar_count; Number of member variables struct objc_ivar ivar_list[1]; Objc_ivar contains member variables of the generic class}

struct Objc_method_list **methodlists: A function pointer to a method linked list structure body

structstruct objc_method_list *obsolete; an obsolete method int  method_count; Number of methods struct objc_method method_list[1]; method linked list structure body}

struct Objc_cache *cache: A pointer to the most recently used method, which will be found in the cache the next time you visit

structint/**/int  occupied; Method buckets[1]; };

struct Objc_protocol_list *protocols: Store the protocol that this class adheres to

structstruct objc_protocol_list *long*list[1];};

SEL type:
Method Selector Class: You can find the corresponding method by the name of the method, each method has a SEL,
If the method name is the same, the SEL for multiple methods is the same

To dynamically invoke a method procedure:

The function finds the corresponding class through ISA at the time of invocation, and now finds the address of the corresponding method through the SEL in the cache table, if not found, then the method list
In the search, if not found, in the superclass to find, step to find, if found, put this method address in the cache, and then do this way

Self-study iOS development-------objective-c Dynamic Call method notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.