【问题标题】:How can I change this method to get rid of the warning without anything changing?如何更改此方法以消除警告而不进行任何更改?
【发布时间】:2014-05-29 15:23:08
【问题描述】:

所以这个问题:Warning-used as the name of the previous parameter rather than as part of the selector

回答了我的部分问题,但我真的不希望在此方法中进行任何更改,而且我对它的工作原理有点困惑。这是整个方法:

-(void) SetRightWrong:(sqzWord *)word: (int) rightWrong
{
if (self.mastered==nil) {
    self.mastered = [[NSMutableArray alloc]initWithCapacity:10];
}

//if right change number right
if (rightWrong == 1) {
    word.numberCorrect++;
     //if 3 right move to masterd list

    [self.onDeck removeObject:word];
    if(word.numberCorrect >= 3 )
    {
        [self.mastered addObject:word];


    }
    else
    {
         //if not 3 right move to end of ondeck
        [self.onDeck addObject:word];

    }


}
else if(rightWrong == 0)
{
    //if wrong remove one from number right unless 0
    NSUInteger i;

    i=[self.onDeck indexOfObject:word];

    word = [self.onDeck objectAtIndex:i];

    if (word.numberCorrect >0) {
         word.numberCorrect--;
    }
}
}

我得到的警告是:'word' 用作前一个参数的名称而不是选择器的一部分。

【问题讨论】:

  • 必须更改您的方法名称,这是无法避免的。您需要使方法类似于:-(void) setRightWrong:(sqzWord *)word withInt:(int)rightWrong 其中word 是您的sqzWord 指针,rightWrong 是您的整数。

标签: objective-c xcode


【解决方案1】:

这是因为你没有给方法的第一个参数命名。就目前而言,您拥有以下内容:

-(void) SetRightWrong:(sqzWord *)word: (int) rightWrong

其中rightWrongword: 参数的名称,但SetRightWrong 参数没有名称。您应该为第一个参数命名,紧跟其类型 (sqzWord *)。

-(void)setRightWrong:(sqzWord *)aWord   word:(int)rightWrong;
   (1)     (2)           (3)     (4)     (5)   (6)  (7)
  1. 返回类型
  2. 方法名的第一部分
  3. 参数类型
  4. 第一个参数
  5. 方法名的第二部分
  6. 参数类型
  7. 第二个参数

【讨论】:

    【解决方案2】:

    您了解问题的实质吗?你说你有点糊涂。所以你很困惑,你得到一个警告,它应该清楚地告诉你有问题,而不是试图解决问题,你想要帮助如何摆脱警告?这是程序员的一种非常令人担忧的态度。

    要解决您的问题:下载一些 Objective-C 示例代码。 任何示例代码。看看 Objective-C 方法是如何命名的。将其与您的 Objective-C 方法的命名方式进行比较。如果你看不出区别,明天再看一遍,在看之前对自己说:“我的代码错了。编译器是对的。我的任务是找出我的代码错的原因。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多