objc_getProtocol()为“NSApplicationDelegate”返回NULL? [英] objc_getProtocol() returns NULL for `NSApplicationDelegate"?
问题描述
我试图使用 objc_getProtocol()
函数来获取对代表 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");
但是,由于某种原因,这总是返回 NULL
。
However, for some reason, this always returns NULL
.
其他协议如 NSObject
, NSCoding
code> NSTableViewDelegate 和 NSTableViewDataSource
工作正常。
Other protocols such as NSObject
, NSCoding
, NSTableViewDelegate
, and NSTableViewDataSource
work fine.
NSApplicationDelegate
有什么特别的吗?或者我做错了什么?
Is there something special about NSApplicationDelegate
, or am I doing something wrong?
推荐答案
在Apple文档中找到答案:
Found the answer in the Apple docs:
编译器为每个遇到的协议声明创建一个协议对象,但前提是协议也是:
The compiler creates a protocol object for each protocol declaration it encounters, but only if the protocol is also:
- / li>
- 或者引用源代码中的某处(使用
@protocol())
这篇关于objc_getProtocol()为“NSApplicationDelegate”返回NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!