如何在我的目标c源文件中临时禁用警告? [英] How do I temporary disable warnings in my objective c source file?

查看:280
本文介绍了如何在我的目标c源文件中临时禁用警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个项目有一个不强制执行警告的构建系统。



但是我有一些需要警告的代码才能工作。这里是一个例子

  NSString * title = @; 
if([view respondsToSelector:@selector(title)]){
title = [view title];
}

经过一些Google搜索后,我试着通过包装代码区来禁用代码块的警告

  #pragma警告禁用
//我的代码
#pragma警告恢复

没有工作:(b / b

任何人都知道如何去做这在Xcode?

任何帮助表示赞赏。



-CV


<解决方案

#pragma GCC诊断推送
#pragma忽略GCC诊断-Wshadow-ivar
/ /你的代码
#pragma GCC诊断弹出

你可以了解 GCC pragma here 并获取警告的警告代码转到日志导航器(Command + 7),选择最上面的内部版本,展开日志(右边的'='按钮),然后滚动到最下面,然后你的警告代码在方括号内,例如<$ c

$ 编辑



对于clang,您可以使用

  #pragma clang diagnostic push 
#pragma clang diagnostic ignored-Wshadow-ivar
//您的代码
#pragma clang诊断弹出窗口


One project I work on has a build system that enforces no warnings.

But I have some code that needs warnings to work. Here is an example

NSString* title = @"";
if ([view respondsToSelector:@selector(title)]) {
  title = [view title];
}

After some googling I tried disable warnings for the code block by wrapping that code area with

#pragma warning disable
// my code
#pragma warning restore

Didn't work :(

Anyone know how to do this in Xcode?

Any help is appreciated.

-CV

解决方案

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow-ivar"
// your code
#pragma GCC diagnostic pop

You can learn about GCC pragma here and to get the warning code of a warning go to the Log Navigator (Command+7), select the topmost build, expand the log (the '=' button on the right), and scroll to the bottom and there your warning code is within square brackets like this [-Wshadow-ivar]


Edit

For clang you can use

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-ivar"
// your code
#pragma clang diagnostic pop

这篇关于如何在我的目标c源文件中临时禁用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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