Xcode警告:未使用的实体问题:未使用的变量

时间:2021-12-15 20:17:20

I'm working on this tutorial application and the code is giving me this warning:

我正在开发这个教程应用程序,代码给了我以下警告:

Xcode WARNING: Unused Entity Issue: Unused Variable

Xcode警告:未使用的实体问题:未使用的变量

It's giving the error when executing this statement:

它在执行这个语句时出错:

int newRowIndex = [self.checklist.items count];

What's causing it? Which steps should I take to resolve this?

是什么导致了它呢?我应该采取哪些步骤来解决这个问题?

4 个解决方案

#1


7  

The variable newRowIndex is initialized but not being used anywhere else.

变量newRowIndex已初始化,但在其他地方不使用。

#2


3  

This warning just means that you created a variable, newRowIndex, but are not using it anywhere.

这个警告仅仅意味着您创建了一个变量newRowIndex,但是没有在任何地方使用它。

To silence the warning, use this int somewhere, like

要使警告无效,可以在某处使用这个int值,比如

int newRowIndex = [self.checklist.items count];
NSLog(@"New Row Index: %i", newRowIndex);

#3


2  

It's probably because your build settings might have warnings flagged as errors.

这可能是因为您的构建设置可能有标记为错误的警告。

You can silence warnings (not advised but if you just want to make sure you can build something) by searching for "Warning Policies" and turning "Treat Warnings as Errors" to "No".

通过搜索“警告策略”并将“将警告视为错误”转换为“否”,您可以使警告保持沉默(不建议这样做,但如果您只是想确保构建一些东西)。

#4


1  

If you really want not to receive such warnings any more do the following:

如果你真的不想再收到这样的警告,请做以下的事:

  1. Go to build settings of your project
  2. 去构建项目的设置
  3. Find "Other Warning Flags" option
  4. 找到“其他警告标志”选项
  5. Remove -Werror and -Wno-unused-parameter
  6. 删除-Werror和-Wno-unused-parameter

#1


7  

The variable newRowIndex is initialized but not being used anywhere else.

变量newRowIndex已初始化,但在其他地方不使用。

#2


3  

This warning just means that you created a variable, newRowIndex, but are not using it anywhere.

这个警告仅仅意味着您创建了一个变量newRowIndex,但是没有在任何地方使用它。

To silence the warning, use this int somewhere, like

要使警告无效,可以在某处使用这个int值,比如

int newRowIndex = [self.checklist.items count];
NSLog(@"New Row Index: %i", newRowIndex);

#3


2  

It's probably because your build settings might have warnings flagged as errors.

这可能是因为您的构建设置可能有标记为错误的警告。

You can silence warnings (not advised but if you just want to make sure you can build something) by searching for "Warning Policies" and turning "Treat Warnings as Errors" to "No".

通过搜索“警告策略”并将“将警告视为错误”转换为“否”,您可以使警告保持沉默(不建议这样做,但如果您只是想确保构建一些东西)。

#4


1  

If you really want not to receive such warnings any more do the following:

如果你真的不想再收到这样的警告,请做以下的事:

  1. Go to build settings of your project
  2. 去构建项目的设置
  3. Find "Other Warning Flags" option
  4. 找到“其他警告标志”选项
  5. Remove -Werror and -Wno-unused-parameter
  6. 删除-Werror和-Wno-unused-parameter