LuisABOL
LuisABOL

Reputation: 2991

GCD objects as Objective-C objects

Grand Central Dispatch objects are said to behave like Objective-C objects when compiled with an Objective-C compiler. But that's a little unclear for me.

Objective-C objects are, in fact, structures which have, at least, one field: a pointer (the isa pointer) to the object's class structure. The other fields, if any, correspond to the object's ivars.

So, can GCD objects be casted to structures whose first field is a pointer to an Objective-C class structure? Since dispatch objects participate in ARC, what does the compiler do: does it send retain and release messages to the objects (like objc_msgSend(obj, @selector(retain)), for example) or does it generate dispatch_object_retain and dispatch_object_release calls? I mean, do GCD objects respond to ObjC messages in the [obj mesg] fashion?

Upvotes: 2

Views: 363

Answers (1)

Catfish_Man
Catfish_Man

Reputation: 41831

GCD objects are actual objects, and the compiler doesn't treat them specially. You can add them to Cocoa collections, po them in the debugger, etc...

However, the runtime does do a bit of special handling for them. Their isa pointer points to the dispatch vtable rather than a regular ObjC class.

Upvotes: 6

Related Questions