Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objc_getProtocol() returns NULL for `NSApplicationDelegate"?

I'm trying to use the objc_getProtocol() function to get a reference to the struct representing the NSApplicationDelegate protocol:

Protocol *protocol = objc_getProtocol("NSApplicationDelegate");

However, for some reason, this always returns NULL.

Other protocols such as NSObject, NSCoding, NSTableViewDelegate, and NSTableViewDataSource work fine.

Is there something special about NSApplicationDelegate, or am I doing something wrong?

like image 660
Greg Brown Avatar asked Nov 04 '22 01:11

Greg Brown


1 Answers

Found the answer in the Apple docs:

http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Chapters/ocProtocols.html#//apple_ref/doc/uid/TP30001163-CH15

The compiler creates a protocol object for each protocol declaration it encounters, but only if the protocol is also:

  • Adopted by a class,
  • Or referred to somewhere in source code (using @protocol())
like image 50
Greg Brown Avatar answered Nov 15 '22 05:11

Greg Brown