错误:委托初始化调用的结果必须立即返回或分配给“自己”。

时间:2011-11-08 22:09:43

标签: cocoa xcode4.2

这是什么意思?我该如何解决?

代码:

- (id)init
{
    [super init];
    firstNumber = random() % 100 + 1;
    secondNumber = random() % 100 + 1;
    return self;
}

错误:

/Users/user/Dropbox/dev/bignerdranch_cocoa/lottery/LotteryEntry.m:15:5:{15:5-15:17}: error: the result of a delegate init call must be immediately returned or assigned to 'self' [4]

1 个答案:

答案 0 :(得分:23)

您的self未创建...

-(id) init {
  self = [super init];
  if(self != nil) {
    // do init stuff
  }
  return self;
}