• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
@property and messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

@property and messages


  • Subject: @property and messages
  • From: Jamie Phelps <email@hidden>
  • Date: Thu, 28 Feb 2008 08:57:57 -0600

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: @property and messages
      • From: Adam P Jenkins <email@hidden>
  • Prev by Date: Combining NSLineBreakByWordWrapping + NSLineBreakByTruncatingTail in NSTextView
  • Next by Date: Re: Value binding not updating on text field
  • Previous by thread: Re: Combining NSLineBreakByWordWrapping + NSLineBreakByTruncatingTail in NSTextView
  • Next by thread: Re: @property and messages
  • Index(es):
    • Date
    • Thread