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

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

    This is not a problem at all in the modern Objective-C. In the modern Objective-C, properties are automatically synthesized and their corresponding instance variables get a _ prefix.

    So, with auto-synthesis your properties would create instance variables _variableName and _comparisonValue. No shadowing occurs in this case.

    More info in this blog post


    If you absolutely need to manually synthesize your properties, rename the sinthesized ivar like this

    @synthesize variableName = _variableName;
    

    In general case, rename your method arguments.

提交回复
热议问题