• 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: dealloc and instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dealloc and instance variables


  • Subject: Re: dealloc and instance variables
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 22 Nov 2003 23:47:29 -1000

On Nov 22, 2003, at 10:55 PM, Graeme Mathieson wrote:
That brings up another thing I'm not entirely sure about. Surely somebody could in fact pass in an NSMutableString and, despite the fact my object thinks its immutable, merrily mess around with my object's data without going through the appropriate accessors? I guess the only way to be sure would be something along the lines of:
- (id)initWithString:(NSString *)aString
{
if((self = [super init])) {
if([aString isMemberOfClass:[NSString class]]) {
baz = [aString retain];
} else {
baz = [aString copy];
}
}
return self;
}

You should get used to using accessor methods throughout:

- (id)initWithString:(NSString *)aString
{
if((self = [super init])) {
[self setBaz:aString];
}
return self;
}

For how to write the accessor method setBaz:, see:
<http://www.stepwise.com/Articles/Technical/2002-06-11.01.html/>

mmalc
_______________________________________________
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.

References: 
 >Re: dealloc and instance variables (From: Jörn Salewski <email@hidden>)
 >Re: dealloc and instance variables (From: Graeme Mathieson <email@hidden>)

  • Prev by Date: Re: Reading from an NSInputStream
  • Next by Date: Re: dealloc and instance variables
  • Previous by thread: Re: dealloc and instance variables
  • Next by thread: Re: dealloc and instance variables
  • Index(es):
    • Date
    • Thread