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

NickFalk

macrumors 6502
Original poster
Jun 9, 2004
347
1
...and I guess it must be right, as I've yet to find me trumping the compiler. :eek:

I am however quite unable to understand why the compiler delivers the following error-message: SquidDrop[13063:207] *** -[__NSDate timeIntervalSinceNow]: message sent to deallocated instance 0xbec4be0


based on the below code:

Code:
	NSMutableArray *lastFiveDays	=	[userDefaults objectForKey:@"lastFiveDays"];
			
	int dateNumber	=	1;	// used to know which of the last five days we are looking at.
	int thisDayNumber;
	
	
	// Here we'll check which date we should compare todays date with
	for (dateNumber = 1;dateNumber < 5;dateNumber++){
				
		NSDate *thisDate	=	[lastFiveDays objectAtIndex: dateNumber];
		
		thisDayNumber		=	[[[NSCalendar currentCalendar] 
							  components: NSWeekdayCalendarUnit 
							  fromDate: thisDate] weekday];
			
		NSDate *lastDate	=	[lastFiveDays objectAtIndex: dateNumber -1];
		
		int lastDayNumber		=	[[[NSCalendar currentCalendar] 
								  components: NSWeekdayCalendarUnit 
								  fromDate: lastDate] weekday];
		

		if (thisDayNumber == lastDayNumber) {
			
		}
	
	}
	

	
	// Now that we know the date we should compare with we can start by doing just that
	
	[B]NSDate *todaysDate		=	[[NSDate alloc]initWithTimeIntervalSinceNow:0];[/B]	// <- The only occurrence of initWithTimeIntervalSinceNow 	

	int todayDayNumber	=	[[[NSCalendar currentCalendar] 
							  components: NSWeekdayCalendarUnit 
							  fromDate: todaysDate] weekday];
	
	BOOL todayShouldBeAddedToTheArray	=	NO;
		
	
	// first we'll rule out the possibility that it's the same day	
	if (thisDayNumber != todayDayNumber) {
		
		if ( (todayDayNumber == thisDayNumber +1) || (todayDayNumber == 1 && thisDayNumber == 7) ) {
			todayShouldBeAddedToTheArray	=	YES;
		}else { // this else meaning there's a gap between the days!
			int dateNumberToReplace		=	0;
			
			for (dateNumberToReplace = 0; dateNumberToReplace < 5; dateNumberToReplace++) {
				[lastFiveDays replaceObjectAtIndex:dateNumberToReplace withObject:todaysDate];
			}
			
		}

	}
	
	
	// now if everything above is in place the flag should be set, so:
	if (todayShouldBeAddedToTheArray) {
		[lastFiveDays replaceObjectAtIndex:dateNumber withObject:todaysDate];
		
		// then we can check if we have reached an achievement
		if (dateNumber == 4) {
			gFiveDaysInRow	=	YES; // Achievement reached, yay!
		}else { // if not we need to fill the rest of the array with today's date
			int counter;
			
			for (counter = dateNumber+1; counter < 4; counter++) {
				[lastFiveDays replaceObjectAtIndex:counter withObject:todaysDate];
			}
			
		}
		
	}
	
	
[B]	[todaysDate release];
[/B]

And for the record, there's no other part of the program containing timeIntervalSinceNow, apart from this, except for the init in the App delegate...
 
*BLUSH*
:eek:

Yes, obviously it does compile. I'm none the wiser though.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.