I have a CLLocation that I set to the current location within the following function
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
currentLocation = newLocation;
}
When I try to access the current position in a later method the app crashes.
NSLog(@"current latitude is %f", currentLocation.coordinate.latitude);
NSString *longitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.longitude];
NSString *latitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.latitude];
The current position is set in the first method. I can print it out, what is weird is that I have this currentLocation defined as a pointer in the header.
The app crashes and there is no stacktrace. The debugger just sends me to the retValue of my app.
I tried retaining the pointer as well as alloc before setting it to the newLocation, but nothing seems to work.
What am I missing 😀
I’m not so sure about your code but I can suggest this
You need to retain newLocation pointer not the currentLocation before setting.
or
Because your assignment
currentLocation = newLocation;does not retain the pointer and newLocation is autorelease.