Objective-C convention to prevent “local declaration hides instance variable” warning

前端 未结 9 1443
滥情空心
滥情空心 2020-12-08 04:50

I am using the following code ...

-(id) initWithVariableName:(NSString*)variableName withComparisonValue:(NSString*)comparisonValue {

    // super init
             


        
9条回答
  •  天涯浪人
    2020-12-08 05:16

    If your method truly is an initialiser, don't forget to do your self = [super init];.

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

    I have never personally encountered a situation where self has changed to nil or another value, but it's the Objective-C Initialiser Idiom™.

提交回复
热议问题