ios - NSDate throwing BAD_EXCESS for what? -
i have below.
@interface myviewcontroller () { nsdate *mycurrentdate; } @implementation myviewcontroller -(void)viewdidload { [super viewdidload]; mycurrentdate = [nsdate date]; } - (ibaction) prevaction:(id)sender { nslog(@"mycurrentdate===%@", mycurrentdate); // here says mycurrentdate = [mycurrentdate datebyaddingtimeinterval:60*60*24*-1]; [self formatdateandpostonbutton]; }
when try print current date below, crash saying bad_excess
nslog(@"mycurrentdate===%@", mycurrentdate);
below screenshot same.
i'm not using arc in project.
any idea going wrong?
since not using arc, easiest way retain objects use generated setters/getters.
instead of:
@interface myviewcontroller () { nsdate *mycurrentdate; }
make
@interface myviewcontroller () @property(nonatomic, retain) nsdate* mycurrentdate; @end
so keep nsdate
retained. right nsdate
gets deallocated when auto-release pool drained.
you need use getters/setters provided, however:
self.mycurrentdate = [self.mycurrentdate datebyaddingtimeinterval:60*60*24*-1];
anyways recommend start using arc make life simpler , avoid strange memory crashes.
Comments
Post a Comment