【问题标题】:Ignore Issue-Type in Xcode 4忽略 Xcode 4 中的问题类型
【发布时间】:2011-05-01 13:38:20
【问题描述】:

我对 xcode4 有一点问题。 我的项目使用这种类型的代码时遇到问题:

- (id)init {
  if (self = [super init]) {
  }
  return self;
}

我知道我可以通过以下方式解决它:

- (id)init {
  if ((self = [super init])) {
  }
  return self;
}

- (id)init {
  self = [self init];
  if (self) {
  }
  return self;
}

但问题是,我在一个特殊项目中使用了大量外部库,我不想编辑这些文件,也不想将更新推送到 github 或其他东西。

那么有没有一个选项可以在 xcode 中停用这种类型的通知/问题发布?

【问题讨论】:

  • 警告说什么?我没有收到此代码的警告。我认为 if 子句中的赋值是代码异味。
  • 上面写着 Using the result of an assignment as a condition without parentheses 。是的,我也不喜欢这种风格。但是第三方库确实使用了这个。

标签: objective-c xcode xcode4 issue-tracking


【解决方案1】:

据我所知,您有两种选择:

  • 切换到 GCC 作为编译器,因为 LLVM 默认会检查此警告,而 GCC 不会

  • -Wno-idiomatic-parentheses 添加到 LLVM 编译器警告/其他警告标志

Clang's Options to Control Error and Warning Messages

【讨论】:

  • 我使用 GCC。尝试在 GCC 上使用 -Wno-idiomatic-parentheses 会引发错误 cc1obj: error: unrecognized command line option "-Wno-idiomatic-parentheses"
  • @choise,不,这是特定于 clang/LLVM 的标志,在 GCC 中不起作用。有趣的是,你得到了 GCC 的错误。您确定每个子项目都设置为使用 GCC 编译器吗?我刚刚尝试使用 GCC 4.2,并没有针对这种情况发出警告。
  • 无法切换到 LLVM 2.0?您确定编译器设置没有被目标覆盖吗?我建议创建一个简单的应用程序模板应用程序并使用初始化代码尝试不同的编译器,看看它的行为是否相同。
  • 还是没有运气。明天再试一次=/
  • 无法对我的项目执行此操作。在我使用 gcc 4.2 的项目的非常目标和内置设置中。我会接受你的回答,因为我认为这是正确的。可能 xcode4 仍然有点错误。谢谢!
【解决方案2】:

您应该使用if(self == [super init]) 而不是if(self = [super init])= 用于给变量添加值,== 的意思是Is equal?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-26
    • 2011-09-22
    • 2016-08-04
    • 1970-01-01
    • 2017-02-03
    • 2011-11-26
    • 1970-01-01
    • 2013-11-14
    相关资源
    最近更新 更多