I need a way to get my user's current location.
Since the user has friends and they also have location data, I believe that the right way is to put the location field in my main db data, both in Friend
and User
objects.
Now, here is what I thought:
You have some kind of location manager, which when I need the exact location, I tell him to start the CLLocationManager
updates. (for which my manager is responsible) The manager will save the location in the user.location field in Db, and the controllers interested in the user information will be registered using KVO for this data. This sounds good to me, in addition to the fact that I have to access this singelton location from every controller that needs an exact location (to tell it to start generating the location, I don't want the location updates all the time) . Plus, I try not to pollute my code with a bunch of calls.
Although it might be wiser to have a location manager as a property inside my User
class. (obviously, if I have several users in memory right now, they will all have the same singelton location manager) I will add another method to the user class and call it “ StartGettingLocation
”, and now that some kind of controller needs in the current exact location, he can do one of the following:
- If I have a User object in my controller (which was passed to another UIViewController), I simply call its "
StartGettingLocation
" method and KVO its field. - If I do not have a User object in my controller, I get it from my database and do as described above.
Does this sound right?
If so, then I'm not sure if it is possible to add a new MyLocationManager member to my User class (which is a subclass of managedObject)? What is the right way to accomplish this?
thanks
source share