I am using the following code ...
-(id) initWithVariableName:(NSString*)variableName withComparisonValue:(NSString*)comparisonValue {
// super init
self = [super init];
if (!self) return nil;
// set instance variables
self.mustExist = NO;
self.reverseCondition = NO;
self.regularExpression = NO;
self.variableName = variableName; // generates warning
self.comparisonValue = comparisonValue; // generates warning
return self;
}
which generated the following two warnings ...
- Local declaration of 'variableName' hides instance variable
- Local declaration of 'comparisonValue' hides instance variable
Is there a common or accepted convention for dealing with these warnings?
I understand that it is simply to inform the user that they should specify an instance when referring to the class member, but its annoying.
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
Either give the local a more descriptive name (e.g. initialVariableName) or give instance variables a different notation (e.g. myClass_variableName). I prefer the latter in most cases because it calls attention to when I'm using class internals rather than the proper interface.
I see this is a fairly old question with a accepted answer but I have a better solution and its code convention.
The convention states that you prefix private variables with a underscore (_varName) and public (like properties) with just the name.
With this you just can call the same variable name in your functions.
Example:
ExampleClass.h
ExampleClass.m