objc_getProtocol() returns NULL for `NSApplicationDelegate"?

社会主义新天地 提交于 2019-12-07 04:37:16

问题


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?


回答1:


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())


来源:https://stackoverflow.com/questions/10212119/objc-getprotocol-returns-null-for-nsapplicationdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!