My class contains an UIImage property which I want to enforce as a 'copy' property by any external clients accessing it. But, when I try to do a copy in my custom setter, I get the runtime error about UIImage not supporting copyWithZone. So what's a good way to ensure that the correct ownership policy is followed?
// declared in the interface as:
@property (nonatomic, readonly, copy) UIImage *personImage;
// class implementation
- (void)setPersonImage:(UIImage *)newImage
{
if (newImage != personImage)
{
[personImage release];
// UIImage doesn't support copyWithZone
personImage = [newImage copy];
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…