I have an instance variable lat (NSString) in my App Delegate. What i want to do is set this variable equal to the user’s current latitude in didUpdateToLocation:fromLocation, such that i can access it from a different view. This is key. So i have this code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
appDelegate = (myProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.lat = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
}
In terms of debugging, when i do po appDelegate.lat in the console, when a breakpoint is set here, then i can see the value fine. When i go to my ViewController where i want to use the value, i get out of scope when i hover over it, and cannot access memory at 0x0 when i try po appDelegate.lat. This is from the view controller:
[appDelegate.locMan startUpdatingLocation];
NSLog(@"here");
NSLog(appDelegate.lat);
Since nothing is getting printed for my NSLog(appDelegate.lat) statement, i can only assume something is wrong.
What would be the correct way to debug this.
Thanks.
Might need to see more code but it sounds like you may not be retaining appDelegate property of the viewController. Certainly the message
cannot access memory at 0x0means a null pointer.If you can see the
latproperty in the application delegate but can’t see it from the viewController then the problem is in the linkage between the appDelegate and the viewController. If you can see the.latin one method of the viewController but not in another one, that suggest theappDelegateattribute of the viewController is not being properly retained.Edit01:
Should add that you can set a breakpoint to log and continue on the
line in the appDelegate source file. This will log every time one of the synthesized accessors/setters is called. This will tell you when the property is actually been accessed or set. You can a debugger function on the same breakpoint to print the value of lat as well.
If you need more info, you can write out explicit accessor/setter methods and put log statements inside them. I doubt you need to go that far in this case.