0

"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?

user007
  • 21
  • 2
  • "opaque" means "you shouldn't care what this actually is". It might be (probably is) a struct describing the class somehow, but you're not supposed to access the struct directly as opposed to using the Objective C runtime functions. – millimoose Oct 27 '13 at 23:52

1 Answers1

0

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.

newacct
  • 119,665
  • 29
  • 163
  • 224
  • @newact: are classes structs or struct pointers? – user007 Oct 29 '13 at 10:10
  • @user007: An *object* (instance of a class) is a struct. In Objective-C, we never hold objects directly; we always use pointers to objects to manipulate objects. So pointers to objects are pointers to structs. A *class object* (again, this is a more advanced concept) is an object, and so is a struct. Again, we can only deal with pointers to class objects, not the class objects themselves. – newacct Oct 29 '13 at 10:30