Re: NSDate And Super Class
Re: NSDate And Super Class
- Subject: Re: NSDate And Super Class
- From: Andy Lee <email@hidden>
- Date: Tue, 24 Feb 2009 22:01:01 -0500
On Feb 24, 2009, at 8:25 PM, Richard Good wrote:
-(DateTest*) init {
[super init];
aDate =[NSDate date];
return self;
}
Wait a minute. I just figured out you're saying the *debugger* says
datesubClass.aDate is out of scope, not the compiler as I thought.
The reason is that you're not retaining aDate in the init method. It
gets deallocated prematurely and the pointer is invalid, hence "out of
scope". Try
aDate = [[NSDate date] retain];
If it's unclear why you need to do this, you need to study memory
management -- it's a prominent chapter in the docs, you should be able
to find it, plus it's linked to many, many times in the list archives.
There are other coding issues: init methods should return id, and they
should check the result of [super init]. There's a chapter on
"writing initializers" or some such -- look for that too.
--Andy
_______________________________________________
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