gpt4 book ai didi

objective-c - 忽略单个文件中的 "Unused Entity Issue: Unused Variable"

转载 作者:太空狗 更新时间:2023-10-30 03:58:50 34 4
gpt4 key购买 nike

我只想在我的 Xcode 项目的一个文件中删除此编译器警告。有办法做到这一点吗?

最佳答案

您可以使用 a pragma directive and the "diagnostic" keyword 关闭 Clang 中的特定警告,像这样:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"

// Insert code here

#pragma clang diagnostic pop

推送和弹出之间的代码不会产生未使用的变量警告。

第二种选择更有针对性,是用 GCC-style attribute 标记特定变量,特别是“未使用”。 Clang 尊重 GCC 的既定属性,不会发出关于该变量的警告:

__attribute__((unused))
NSString * thisStringIsJustForFun = @"It's only work if somebody makes you do it.";

关于objective-c - 忽略单个文件中的 "Unused Entity Issue: Unused Variable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18423449/

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