objc_getProtocol()为“NSApplicationDelegate”返回NULL? [英] objc_getProtocol() returns NULL for `NSApplicationDelegate"?

查看:241
本文介绍了objc_getProtocol()为“NSApplicationDelegate”返回NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 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:

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:


  • / li>
  • 或者引用源代码中的某处(使用
    @protocol())

这篇关于objc_getProtocol()为“NSApplicationDelegate”返回NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆