سؤال

I'm trying to save on memory the self.mapView.userLocation.location in CLLocation property but after I assign the value to the property and I check the value of the property I get this:

<+0.00000000,+0.00000000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 1/19/14 4:21:14

Here is my code:

.h:

@property (retain, nonatomic) CLLocation *currentlocation;

on my .m

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    if (self.currentlocation != self.mapView.userLocation.location)
    {
       self.currentlocation = self.mapView.userLocation.location;
    }

}

My question is who can I retain the value of self.mapView.userLocation.location on self.currentlocation and keep it on memory?

I'll really appreciate you help.

هل كانت مفيدة؟

المحلول

You are assigning a pointer to another pointer. So you are actually just storing a reference to the MKUserLocation's location.

It sounds like you want to store the value at that time, not wanting it to change. If so:

 self.currentLocation = [self.mapView.userLocation.location copy];

Storing a copy should get you what you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top