I have following simple class:
@interface Article: NSObject {
NSString *title;
}
@property (copy, nonatomic) NSString *title;
@end
@implementation
- (void)setTitle:(NSString *)aString {
if ((!title && !aString) || (title && aString && [title isEqualToString:aString])) return;
dirty = YES;
[title release];
title = [aString copy];
}
- (NSString *)title {
return title;
}
@end
In my application I have to do a lot of things like
Article *article= [objectsArray getObjectAtIndex:x]; NSString *title=article.title; UILabel.text=title; [title release];
I know I'm supposed to call retain when I get the property:
NSString *title=[article.title retain];
Maybe I am lazy to do a retain where I get the propery. Or If I need to do that tens of times all over the applicaiton.
Can I have getter to return a copy?
- (NSString *)title {
return [title copy];
}