我有一个关于覆盖自动生成存取器方法的问题。以下将无法工作(我相信),因为每个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;
}
我要强调的是,这里所呈现的图像的使用是一个例子,关于如何在这个特殊的例子做的想法是不是在一般情况下不太重要。
它是循环的事实是我的问题源于。 – 2010-09-14 07:15:46