By now, most of you know I'm working through Aaron Hillegass's book. Along the way, I'm trying to utilize Objective-C 2.0 constructs where I am aware of differences. Hillegass is using explicitly declared setters and getters. I am using @property and @synthesize. In his - (void)setString: method, he writes

- (void)setString:(NSString *)c
{
        c = [c copy];
        [string release];
        string = c;
        NSLog(@"The string: %@", string);
        [self setNeedsDisplay:YES];
}

I have declared my property like this

@property (copy) NSString * string;

So, now I can call self.string = newstring; Great. But it seems that if I do this, I'll be writing the last two lines of the explicit setter each time I change the string. For simple projects, this is obviously not a big deal, but I am curious how to deal with this as projects get larger. Repetitive code would eventually be a maintenance nightmare.

Obviously there isn't anything to stop me from writing the explicit setter, but I wanted to check with the list and see if there is a more elegant way to handle this issue. Should I write the setter explicitly and then continue to use the dot syntax for getting?

Thanks as always for your help.

Jamie
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to