Pretty much all viewcontrollers in the app I’m building needs a CLLocationManager. Is there any reason not to put it into a global variable (by way of a static class)? The alternative seems to be to set it up separately for every viewcontroller (wasteful) or pass it along to every viewcontroller (messy).
Pretty much all viewcontrollers in the app I’m building needs a CLLocationManager. Is there
Share
I usually setup a shared instance and call it….”LocationManager”. You can check out an old revision here:
https://gist.github.com/1603316
Xamarin Mobile API is also another good project to get synced up with. The goal is to create a shared library that abstracts away the common interfaces to things like GPS, Accelerometer, Contacts, etc:
http://blog.xamarin.com/2011/11/22/introducing-the-xamarin-mobile-api/
Update: to answer your question the only reason I can think of to NOT to create a shared instance implementation is if you plan on accessing it from a bunch of different threads. To solve for this in my implementation I would simply create thread-safe members with thread-safe access patterns to those members.