dontWatchMyProfile
dontWatchMyProfile

Reputation: 46410

What exactly is Class?

From the headers:

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

I do get what id is. It's a struct which has only one member: isa, from type Class. And Class is redirected to obj_class, or what? And obj_class seems to be a zombie. Can't figure out what it is. So what is Class in reality? Just a plain old structure? What's in there?

Upvotes: 4

Views: 292

Answers (1)

Jack
Jack

Reputation: 133669

Yes, Class is a struct that contains all the info needed for that particular class. It is how you can implement an object-oriented paradigm in an environment, like C, that does not allow it by default.

I would suggest you to give a look to Object-Oriented Programming with ANSI C (PDF), it explains in a well complex way how you can implement objective-oriented in C.

Usually that Class struct will contains things like:

    Class super_class   
    const char *name   
    long version           
    long info        
    long instance_size  
    struct objc_ivar_list *ivars  
    struct objc_method_list **methodLists 
    struct objc_cache *cache
    struct objc_protocol_list *protocols

I'm referencing to ObjectiveC itself (this is in /usr/include/objc/runtime.h). This is how a class was defined UNTIL ObjC 2.0. It is just to give you the idea..

This struct is needed to allow RTTI, dynamic invokation and inheritance, otherwise you won't need to know which object you are using at runtime (having a pointer to its Class definition).

Remember that ObjC is a superset of C, so every feature it has exploits C by building complex OOP over it..

Upvotes: 3

Related Questions