gpt4 book ai didi

iphone - 局部声明隐藏实例变量警告

转载 作者:可可西里 更新时间:2023-11-01 06:23:45 26 4
gpt4 key购买 nike

局部声明隐藏了“self.treatmentId = treatmentId;”附近的实例变量消息弹出窗口和“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

最佳答案

将您的代码更改为以下内容。

@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

通过声明局部变量 trentmentNametreatmentId,您实际上失去了通过它们的名称访问全局变量 (iVars) 的能力。

关于iphone - 局部声明隐藏实例变量警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8470502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com