警告:"'myAge' used as the name of the previous parameter rather than as part of the selected"



我已经到处找过了,但仍然无法修复这个警告。

接口:

-(void) myInfo: (int) myAge: (int) myHeight;

我知道这只是一个警告,但我不知道为什么会这样。任何帮助都是感激的。谢谢你。

要去掉这个警告,可以这样声明函数:

- (void) myInfo:(int)myAge height:(int)myHeight;

这将为您提供一个方法,您可以使用以下语法调用该方法(假设该方法是从声明该方法的类中调用的):

[self myInfo:10 height:100]

请参阅以下URL的"方法可以接受参数"一节:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW5,以获得详细的解释。

为方便起见,此处为相关部分:

如果你需要提供多个参数,语法也与C完全不同。C函数的多个参数在圆括号内指定,用逗号分隔;在Objective-C中,带有两个参数的方法声明如下:

- (void)someMethodWithFirstValue:(SomeType)value1 secondValue:(AnotherType)value2;

在本例中,value1和value2是实现中用来访问调用方法时提供的值的名称,就好像它们是变量一样。

或者您可以在整个项目的pch文件中"修复"它

#pragma clang diagnostic ignored "-Wmissing-selector-name"

相关内容

最新更新