Re: Q: how do you generate get/set methods?
Re: Q: how do you generate get/set methods?
- Subject: Re: Q: how do you generate get/set methods?
- From: Alexander Spohr <email@hidden>
- Date: Sat, 17 Jan 2004 16:24:12 +0100
Am 17.01.2004 um 16:04 schrieb M. Uli Kusterer:
At 14:42 Uhr +0100 17.01.2004, Alexander Spohr wrote:
a simple question to all:
how do you generate init/get/set/dealloc declarations and methods for
ivars?
do you type them by hand for every ivar?
i hate writing that stuff again and again by hand :)
Well, I just use the scripts to do that which come with xCode. Select
the ivars in the header and choose the appropriate item from the menu
with the icon that looks like an AppleScript scroll.
um... i seem to be blind sometimes.
but it generates copies? i don't want to start a new discussion about
that but is that what everybody uses? do i really want to have a copy?
- (NSString *)message {
return [[message retain] autorelease];
}
- (void)setMessage:(NSString *)newMessage {
if (message != newMessage) {
[message release];
message = [newMessage copy];
}
}
i do this instead:
- (void)setMessage:(NSString *)anObject
{
[anObject retain];
[message release];
message = anObject;
}
- (NSString *)message
{
return message;
}
maybe i should include the if (message != newMessage)
hm.. the [[message retain] autorelease] looks better than my
implementation.
keeps the object healthy if you do
NSString *x = [that message];
[that setMessage:nil];
[x description]; // kills it, because x might be completely released
here
atze
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.