• 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: NSDate Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSDate Question
      • From: Roland Torres <email@hidden>
References: 
 >NSDate Question (From: Matt <email@hidden>)

  • Prev by Date: Re: _NSKeyValueObservationInfoCreateByRemoving crash in CFRetain()
  • Next by Date: Re: Core Data, using refreshObject:mergeChanges: to trim a portion of my object graph and regain memory... PLEASE HELP!!!!!!!
  • Previous by thread: Re: NSDate Question
  • Next by thread: Re: NSDate Question
  • Index(es):
    • Date
    • Thread