gpt4 book ai didi

ios - 协议(protocol)前向声明的警告是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:30 26 4
gpt4 key购买 nike

我只是想避免警告(没有编译器抑制),但不想在我的文件中添加一些包含。这是我的代码:

@protocol MyProto;

// ...

Protocol *p = @protocol(MyProto);

这是我收到的警告:

@protocol is using a forward protocol declaration of MyProto [-Wat-protocol]

最佳答案

使用协议(protocol)文字 (@protocol) 需要在编译时链接到协议(protocol),这需要编译器查看协议(protocol)的定义。

我不明白您为什么反对“向我的文件添加一些包含”。在使用那个东西的实现文件中包含定义某些东西的头文件是很正常的。应该没有缺点。

如果您想在运行时从字符串中查找协议(protocol),您可以执行类似NSProtocolFromString(@"MyProto") 的操作。

关于ios - 协议(protocol)前向声明的警告是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36257919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com