@interface Article : NSObject
@property (nonatomic, strong) NSString *imageURLString;
@end
@implementation Class
@synthesize imageURLString = _imageURLString;
- (void)setImageURLString:(NSString *)imageURLString {
_imageURLString = imageURLString;
//do something else
}
Did I correctly override the setter when ARC is enabled?
Expanding on the answer given by @Pascal I'd just like to add that it's definitely the right thing to do and you can check by seeing what the code compiles down to. I wrote a blog post about how to go about checking, but basically that code compiles down to (ARMv7):
Note the call to
_objc_storeStrong
which according to LLVM does this:So, to answer your question, yes that's right. ARC has added in the correct release of the old value and retain of the new value.
[Probably over complicated answer, but thought it was useful to show how you can go about answering this sort of ARC related question for yourself in future]
Yes, this is correct. Also took me a while to trust that this is indeed the right thing to do.
You do realize that in this case, the override is not necessary as you don't do more than the standard generated setter would do? Only if you add more code to
setImageURLString:
would you need to override the setter.Call
That's it