My understanding is that objects and classes in Objective-C are just structs.
Respectively they are just:
struct objc_class *
and:
struct objc_object *
Question #1:
objc_msgSend(id self, SEL _cmd);
id
as far as I know is of type struct objc_object *
But when we call a class method, a class, which is of type struct objc_class *
,
I would expect it to cause problem or shout out some kind of warning such as „Hey, wrong type here, my friend“.
But there isn’t.
- Why?
This only serves to fulfill my curiosity, because even without fully understanding this, it doesn’t seem to cause me any trouble (so far). But I would like to dig deep and learn the fundamentals / „peculiarities".
Question #2:
Since there is no warning according to my experience (relates to Question #1), hence my not-so-sure assumption that they could perhaps be used interchangeably.
Can struct objc_class *
and struct objc_object *
really be used interchangeably?
If yes:
Can you show me a scenario and a sample when / how / why we would need to use these interchangeably?
What would be the benefit (if any), disadvantages (if any) and „gotchas“ (things to watch out for; if any) doing so?