In the previous article, we talked about classes and metaclasses. We already know that the essence of a class is the structure objc_class. Next, let's see what objc_class is. objc_class.pngisa points to the metaclass, and super_class represents the parent class of the current class. We are already familiar with these two members and will not go into details here (see Class and Metaclass, Reference). name: class name
The names of the members of the structure are self-explanatory, so we will not explain them one by one. As you can see, ivars is actually a linked list that stores information related to member variables in a class.
See the self-nesting of the structure again, and you can see that methodLists is also a linked list, storing information about the methods in the class. Because it is a secondary pointer, the methods in the class can be modified dynamically, which is also the implementation principle of classification. Here we need to explain SEL and IMP:
Let’s look at the following example. - (void)helloWorld:(int)flag; - (void)helloWorld:(float)flag; In OC, this will result in an error message, and the error type is duplicate declaration. If you write: - (int)helloWorld:(int)flag; - (float)helloWorld:(float)flag; Even though the return values are different, they are still repeated declarations. Because their method names are the same, helloWorld:, these four methods correspond to the same SEL. Since the method names are the same, the IDs are the same. If two classes that are not in an inheritance relationship have methods with the same method name, how do we determine which class’s method to execute? id objc_msgSend(id self, SEL op, ...) [receiver message] There is also a receiver. Even if the ID is the same, different receivers will locate different methods, and methods with the same method name are not allowed to exist in each category, thus ensuring security.
Back to objc_class.
|
<<: Is the decline inevitable? With less than 1% market share, what happened to Microsoft WP?
>>: Real-time display of iOS UI code writing effect
At 4:30 a.m. Beijing time on September 23, Tesla ...
Audit expert: Sun Tao National Psychological Coun...
Preface Although it is called a preface, it is ac...
Functional classification: Life Supported platfor...
For a website optimization SEO personnel, it is v...
Many people believe that open source is the futur...
Straight to the point, this article will summariz...
[[150475]] Many years ago, viruses (programs) wer...
The C-end is for all users and can be used by any...
In the Chinese SUV market, which is like a flouri...
After this upgrade, users can finally simply proc...
How much does it cost to be an agent of an agricu...
The Economic Information Daily reporter learned o...
Taoke Park Lao Hu and major team leaders teach yo...
At the World Internet Conference in Wuzhen these ...