0

我构建了一个名为 game 的自定义类:

。H

-(void) init;

在这里我有一个还找到'-(void) init'

.m

    -(void) init {
    [super init];
    score = 0;
    lives = 3;

    elements = [[NSMutableArray alloc] initWithCapacity:1000];
}

当我尝试使用以下方法初始化对象时:

myGame = [[Game alloc] init];

我得到“找到多个名为'-init'的方法所以我不知道错误在哪里......

4

1 回答 1

3

init should always return (id). Change your function to the following:

.h

-(id) init;

.m

-(id) init {
    if((self = [super init]))
    {
        score = 0;
        lives = 3;

        elements = [[NSMutableArray alloc] initWithCapacity:1000];
    }

    return self;
}
于 2011-02-08T11:57:06.193 回答