• 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
Re: Q: how do you generate get/set methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Q: how do you generate get/set methods?
      • From: "M. Uli Kusterer" <email@hidden>
    • Re: Q: how do you generate get/set methods?
      • From: Jim Correia <email@hidden>
References: 
 >Q: how do you generate get/set methods? (From: Alexander Spohr <email@hidden>)
 >Re: Q: how do you generate get/set methods? (From: "M. Uli Kusterer" <email@hidden>)

  • Prev by Date: Flipped coordinates for compositeToPoint:?
  • Next by Date: Re: Q: how do you generate get/set methods?
  • Previous by thread: Re: Q: how do you generate get/set methods?
  • Next by thread: Re: Q: how do you generate get/set methods?
  • Index(es):
    • Date
    • Thread