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.

enter image description here

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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -