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

前端 未结 9 1441
滥情空心
滥情空心 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:29

    If you are using local instance variable name same as global instance variable name then this warning occur.

    First Methode: For ignoring this warning use have to change local instance variable name or else change the global instance variable name.

    Second Methode: if you want to use global variable then call as self->variableName

    -(id) initWithVariableName:(NSString*)variableName withComparisonValue:(NSString*)comparisonValue {
    
        // super init
        self = [super init];
        if (!self) return nil;
    
        // set instance variables
        self->variableName = variableName; //point to global variableName
        self->comparisonValue = comparisonValue; //point to global comparisonValue
    
        return self;
    }
    

提交回复
热议问题