I have a (retained) UIImage property that is being used to hold a user selected image.
This is the code I have at present when the user makes a selection:
- (IBAction) selectImage1 {
UIImage *image = [UIImage imageNamed: @"image1-big.png"];
self.bigImage = image;
}
but I’m wondering if it is possible to omit the use of the temporary variable convenience method and just do this:
- (IBAction) selectImage1 {
self.bigImage = [UIImage imageNamed: @"image1-big.png"];
}
If there are problems with this second method (I’m guessing something to do with memory management), could someone please explain?
Thank you!
The second way is perfectly fine. The line
UIImage *image = [UIImage imageNamed: @"image1-big.png"];gives you a variableimagethat is auto-released. Assigning it to your ivar via theself.bigImage = imagecallsbigImage‘s setter method which retains the value. Thus the lineself.bigImage = [UIImage imageNamed: @"image1-big.png"];is equivalent to the more verbose way.