Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ipadzero

macrumors newbie
Original poster
Oct 23, 2011
7
0
Hi, I'm doing an application on my Ipad, I'm using NSDate to calculate time interval between 2 touches as below :

in MyFile.h
Code:
@interface MyFile: CCLayer {
     NSDate* startTime;
{
@end
in MyFile.m
Code:
-(id) init 
{
    .........
    startTime = [NSDate date];  //initialize
    ..........
}


-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
        NSTimeInterval timeInterval = [startTime timeIntervalSinceNow];
        startTime= [NSDate date];
        if(timeInterval..........)
                 return FALSE;
        
}


Program received EXC_BAD_ACCESS at:
NSTimeInterval timeInterval = [startTime timeIntervalSinceNow];

I'm not sure what I'm doing wrong here. Thanks for help.
 
startDate = [NSDate date] is an autoreleased object which means it will be destroyed at the end of the init cycle. You might want to [ retain] it.
 
Thanks , it worked :)

Since you retained it, did you do the other thing you need to do?
Do you know what other thing you need to do?
If not, did you read the memory management guidelines?
If not, will you drop everything and read them?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.