开发者

Also found '-(void) init'

开发者 https://www.devze.com 2023-02-09 00:50 出处:网络
I built a custom class named game: .h -(void) init; here I have a Also found \'-(void) init\' .m -(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

精彩评论

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

关注公众号