IPhone: How to save location (CLLocationCoordinate2D) inside a class without memory leak?

I am creating a library that contains an API for setting the current location based on some value collected by GPS. I want to keep this location in my class, and then change the behavior of my library, if installed.

I mean:

@interface myLib
{
@property (nonatomic, retain) CLLocationCoordinate2D *location;
}

@implementation myLib
{
@synthesize location = _location;

- (void)setLocation:(CLLocationCoordinate2D *)loc {
location = loc;
}

- (void)someFunc {
 if (location != nil) ...  
}

}

However, saving is not a valid property for a CLLocationCoordinate2D object.

So, what is the right way to save CLLocationCoordinate2D for later use without memory loss?

Thanks in advance!

+3
source share
2 answers

CLLocationCoordinate2D - -. NSObject, retain ed. ,

CLLocationCoordinate2D location;

, :

@property (nonatomic, assign) CLLocationCoordinate2D location;

setLocation: :

- (void)setLocation:(CLLocationCoordinate2D)newLocation {
    location = newLocation;
    // other stuff
}

setLocation: , . , , - , , .

+13

@synthesize .

- (void) setLocation: (CLLocationCoordinate2D *) loc { location = loc; }

, "" , "" .

, .

0
source

Source: https://habr.com/ru/post/1736007/


All Articles