ios - NSMangedObject not letting access an objects data -


i using coredata , have nsmanagedobject of type thing. when set breakpoint can console "po athing" , shows data stored.

{     thingid = 5181c56063ab02c4d1000016;     distance = "2.075121";     lat = "37.815834";     lng = "-122.406417"; } 

but, if try access lat or lng (which doubles in core data). "nan" returned. if try "po athing.lat" console shows nan.

if try "po athing.thingid" console shows 5181c56063ab02c4d1000016.

if try assign newthing.lat = athing.lat newthing.lat becomes nan.

i guessing has data double?

update:

here how .h had properties

@property (nonatomic) double lat; @property (nonatomic) double lng; 

here how using them

coordinate.latitude = thing.lat; coordinate.longitude = thing.lng; 

here how changed them

@property (nonatomic) double *lat; @property (nonatomic) double *lng; 

and how use them , seems work

coordinate.latitude = *(thing.lat); coordinate.longitude = *(thing.lng); 

as said in comments above, switch "double" "nsnumber", , convert double nsnumber [nsnumber numberwithdouble:somedouble]

or.... (and better) approach (as found in apple documentation) can keep "lat" double, under hood, make own getter/setter , convert double nsnumber.

some.h @property long lat;  some.m @interface mymanagedobject (primitiveaccessors) @property (nonatomic) nsnumber primitivelat; @end   - (long)lat {      [self willaccessvalueforkey:@"lat"];     nsnumber *tmpvalue = [self primitivelat];     [self didaccessvalueforkey:@"lat"];     return (tmpvalue!=nil) ? [tmpvalue longvalue] : 0.0; // or suitable representation nil. }  - (void)setlat:(long)value {      nsnumber *temp = @(value);     [self willchangevalueforkey:@"lat"];     [self setprimitivelat:temp];     [self didchangevalueforkey:@"lat"]; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -