In Cocoa, how is the id type defined?

后端 未结 5 979
孤独总比滥情好
孤独总比滥情好 2020-12-09 06:02

This question is out of pure curiosity. How does Cocoa define the id type? Is it just a typedef for a void *? Also, if you know which header file it is defined in, I would b

5条回答
  •  佛祖请我去吃肉
    2020-12-09 06:19

    in objc.h

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

    To find out on your own, in XCode, right click id -- or any other type -- and select Jump to definition. It's interesting to note the similarities to other C/C++ based object systems; an object pointer -- an id -- points to a struct that starts with a point to shared class information. I many C++ implementations, that would be the virtual function table, as it would be with Microsoft's COM. In Cocoa, the particulars of objc_class aren't revealed to us in the header file.

提交回复
热议问题