"Class" is said to be the opaque type of a class. What does it mean? Is it the type of a class?
One more thing, are classes pointers to structs or basically structs?
"Class" is said to be the opaque type of a class. What does it mean? Is it the type of a class?
One more thing, are classes pointers to structs or basically structs?
A variable of Class
type can hold a pointer to a class object, just like a variable of id
type can hold a pointer to any object. A class object is an object. If you have a variable of type id
, you don't know what kind of thing is in it; the same with Class
. You just know that it's an object. I don't know where you got this "opaque type" term from.
You can say that objects are structs, since they consist of a bunch of things laid out together in a certain way in memory. But you should never care about the internal structure of objects. That's an implementation detail of the runtime. The structs you see in the Apple runtime headers, like objc_object
, objc_class
, etc. are not exactly what the object is -- they represent the structure of the "beginning" of an object in the Apple runtime; but objects contain more stuff beyond what those structs describe, like its instance variables.