I have a method which has suddenly started giving me some problems. It starts like this:
Code:
- (double) calcJulianDayNumber: (NSDate *) dateToConvert {
// Get the day, month and year
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M"];
double month = [[dateFormatter stringFromDate:dateToConvert] doubleValue];
[dateFormatter setDateFormat:@"YYYY"];
double year = [[dateFormatter stringFromDate:dateToConvert] doubleValue];
[dateFormatter setDateFormat:@"d"];
double day = [[dateFormatter stringFromDate:dateToConvert] doubleValue];
[dateFormatter release];
// Work out Julian Date / Julian Day Number
...
And is called like this, in the same class:
Code:
- (void) refresh: (NSDate *) dateToRefreshTo {
workingJDN = [self calcJulianDayNumber:dateToRefreshTo];
...
However, when I run the code, the iPhone simulator crashes. The debugger tells me that 'dateToConvert' on the line
Code:
double month = [[dateFormatter stringFromDate:dateToConvert] doubleValue];
is "Out of scope".
The only problem I can think is that I'm calling refresh:aDate from a different class. This could mean that if I'm passing things by reference rather than by value, then in the methods above I'm trying to access a variable which belongs to the calling class, not self. Which I guess isn't allowed. Right?
As you can tell, I'm new to all of this! Any guidance or general thoughts would be much appreciated!