Obj-C, Instance variable used while 'self' is not set to the result of '[(super or self) init…]'

前端 未结 1 911
谎友^
谎友^ 2021-01-06 08:23

I know I asked a similar question to this not long ago, but I\'m still a little unsure about it. The same sort of thing happens in several places.

Instance variable

相关标签:
1条回答
  • 2021-01-06 08:52

    Generally, you're supposed to write:

    self = [super init...];  // Potentially change "self"
    if (self) {
        something = x;
        another = y;
    }
    return self;
    

    This is because init may not return the original self value in some cases.

    0 讨论(0)
提交回复
热议问题