开发者

Also found '-(void) init'

I built a custom class named game:

.h

-(void) init;

here I have a Also found '-(void) init'

.m

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

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

when I try to开发者_如何学Python initialize a object with:

myGame = [[Game alloc] init];

I got "Multiple methods named '-init' found So I don't know where the error is...


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜