Re: NSDate Question
Re: NSDate Question
- Subject: Re: NSDate Question
- From: "Sean McBride" <email@hidden>
- Date: Fri, 8 Dec 2006 11:15:43 -0500
- Organization: Rogue Research
On 2006-12-07 22:22, Matt said:
>The date prints fine in the init method but I get stuff like
>"21397505" when you click the button. This is driving me crazy
>because I don't see why in the world this code wouldn't work.
>
>
>- (id) init {
> self = [super init];
> if (self != nil) {
> myDate = [NSDate date];
> NSLog(@"%@", myDate);
> }
> return self;
>}
>
>-(IBAction)buttonSetsDate:(id)sender {
> NSLog(@"%@", myDate);
>}
Others have pointed out your problem.... I just want to add that if you
use accessor methods instead of setting the instance variable directly,
you will find that you won't have this problem as often. For example:
- (NSDate *)myDate
{
return myDate;
}
- (void)setMyDate:(NSDate *)aMyDate
{
if (myDate != aMyDate) {
[myDate release];
myDate = [aMyDate copy];
}
}
then:
- (id) init {
self = [super init];
if (self != nil) {
[self setMyDate:[NSDate date]];
NSLog(@"%@", myDate);
}
return self;
}
Check out <http://www.kevincallahan.org/software/accessorizer.html> to help.
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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