我有一个关于覆盖自动生成的访问器方法的问题。以下方法不起作用(我相信),因为每个 getter 都引用了另一个 getter。有没有规定访问器方法不应该使用其他访问器方法,或者您只需要单独注意这些情况?
-(UIImage *) image{
if(image == nil){
if(self.data == nil){
[self performSelectorInBackground: @selector(loadImage) withObject: nil]
}else{
self.image = [UIImage imageWithData: self.data];
}
}
return image;
}
-(NSData *) data {
if(data == nil){
if(self.image == nil){
[self performSelectorInBackground: @selector(loadData) withObject: nil]
}else{
self.data = UIImageJPEGRepresentation(self.image, 0.85);
}
}
return data;
}
我必须强调,这里介绍的图像使用只是一个示例,在这个特定示例中关于做什么的想法不如在一般情况下重要。