Re: dealloc and instance variables
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.