0

I want to get all the classes in my project userLocation variable. How can I identify as a global? Is that reasonable? Do I have to define each class separately? Also I would like to access the application in the background too.

Thanks

Okan
  • 1,133
  • 8
  • 15

2 Answers2

0

Never use global variables in general (in any programming langage), that's bad architecture/design in general.

You should use the Singleton Pattern (see Apple Doc) for such stuff of gathering common information or features global to the application. Use it parcimoniously (using it everywhere without justification is also bad design)

In the case of the userLocation, you can anyway get the latest user location retrieved by the GPS using CLLocationManager's location property anyway, so there is no need for a global variable or a singleton for this case.

AliSoftware
  • 32,623
  • 6
  • 82
  • 77
  • Thank you for the reply. When I need I'm using Singleton Patterns. For my curiosity, and a question I asked for a better architecture. Thank you again. – Okan Nov 02 '11 at 16:31
0

It is not recommended to create many CLLocationManager's instances. Instead, I am usually using the appDelegate to hold the single instance. You can also take a look at CLLocationManager in a single instance tutorial which demonstrate how to use the appDelegate.

As for accessing the application from the background - it depends on what you want to do. can you elaborate what exactly do you want to achieve?

hungary54
  • 767
  • 8
  • 11