I am new to iOS development and trying to build an app that uses user location in multiple view controllers. I am trying to implement the location manager in one separate class, and then send the location from the call back function to the view controllers, whenever there is a new location available. I have seen an implementation that uses singleton but wanted to use protocol methods instead - I have seen in the past such an example, which I can't find anymore, and it worked really well.
Could people advise on what's the best way to design it in such a way? Here are some key parts from one of my view controllers and the location manager class, for reference.
ViewController.m
- (void)viewDidLoad {
locMan = [[LocClass alloc] init];
[locMan startLocationManager];
...
}
LocClass.m (the location manager class)
- (void)startLocationManager {
[self.coreLocationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
//the usual stuff here...
}
How could I use protocol methods to send back the location from didUpdateLocations: to ViewController.m when it's available? Referencing an example would be great if possible.