tags:

views:

22

answers:

1

I have CLLocation variable declared i gave it a value but when i use it at other place, app crash with "Debugging Terminated" without any logs in console

CLLocation *userLoc;

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    userLoc=newLocation;
    [self somefunction];
}
-(void) somefunction
{
NSLog(@"%@",userLoc);
}

here it log userLoc properly

but in my other method

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
{
NSLog(@"%@",userLoc);
}

here app crash. Please help

+1  A: 

Core Location provides you with autoreleased CLLocation object in delegates method, so it becomes invalid outside that method. To preserve it you need to retain location value:

userLoc=[newLocation retain];

Or, better, declare a property for your userLoc variable with retain attribute and use it the following way:

self.userLoc = newLocation;

P.S. Memory management guide is really a must-read...

Vladimir
i dont have reputation to vote ur answer up...but +1 for ur answer..clearly understood
Iphone_bharat