3
votes

local declaration hides instance variable message popup near "self.treatmentId = treatmentId;" and "self.treatmentName = treatmentName;";

@implementation Treatment

@synthesize treatmentId;
@synthesize treatmentName;

-(Treatment *)initWithtreatmentName:(NSString *)treatmentName treatmentId:(NSString *)treatmentId{


    if((self = [super init])){
        self.treatmentId = treatmentId;
        self.treatmentName = treatmentName;
    }

    return self;

 }

@end
2
change the first parameter name in initWithtreatmentName method . - Narayana
modify below method -(Treatment *)initWithtreatmentName:(NSString *)treatmentName treatmentId:(NSString *)treatmentId as something like this -(Treatment *)initWithtreatmentName:(NSString *)otreatmentName treatmentId:(NSString *)otreatmentId ,your instance name and parameter name same thats way warning appearing. - ajay

2 Answers

9
votes

Change your code to the following.

@implementation Treatment

@synthesize treatmentId;
@synthesize treatmentName;

-(Treatment *)initWithtreatmentName:(NSString *)newTreatmentName treatmentId:(NSString  *)newTreatmentId{


    if((self = [super init])){
        self.treatmentId = newTreatmentId;
        self.treatmentName = newTreatmentName;
    }

    return self;

 }

@end

By declaring the local variable trentmentName and treatmentId you are essentially losing the ability to access the global (iVars) via their names.

0
votes

This error means that self.treatmentName and self.treatmentID have been declared previously so the local declaration is hiding the instance variables. If you simply change your init method to:

-(Treatment *)initWithtreatmentName:(NSString *)name treatmentId:(NSString *)identifiction

and your implementation of the method to reflect this, you'll find that the error should go away.