A, objc_getClass

First let’s look at the internal implementation of objc_getClass: Objc_getClass (const char * _Nonnull name) Returns the class definition of a specified class. Take a look at the screenshot below

From here we can see that the runtime is relevant, we can view the analysis from Apple’s open source source

(Source link download link go to objc directory and open the download with the largest number, which represents the latest)

As you can see from the screenshot and description above, the class name is passed in as a string and the corresponding class object is returned.

(Take a look at the corresponding implementation of look_up_class for those interested.)

2. Object_getclass

The first thing we know about NSObject is that there are three types of objects: instance, class, and meta-class. First look at the source code implementation

As you can see here, it returns an ISA pointer. If the obj passed is instance, return the class object; If a class object is passed in, return a meta-class object; If a meta-class object is passed in, return the meta-class object of NSObject.

Paste the debug code below:

Conclusion:

1.objc_getClass(const char * _Nonnull name)

A. Pass in the string class name and return the corresponding class object

2.object_getclass

A. The obj passed may be an instance object, a class object, or a meta-class object

B. If instance object, return class object

C. If it is a class object, a meta-class object is returned

D. If it is a meta-class object, return the meta-class object of NSObject.

Next I’ll introduce the differences between instance objects, class objects, and meta-class objects! If interested, please follow me 😄!