Problem storing coordinates
I'm doing the following to store the longitude and latitude of a location in a custom (NSManagedObject) Bookmark object:
CLLocationCoordinate2D coordinate = [location coordinate];
// Set bookmark variables.
[bookmark setLatitude:[NSNumber numberWithDouble:coordinate.latitude]];
[bookmark setLongitude:[NSNumber numberWithDouble:coordinate.longitude]];
But something goes amiss along the way, and printing out the values of coordinate and bookmark yields this:
2011-03-09 12:56:30.793 XXXXXX[562:307] 55.615258, 12.985627 <- coordinate
2011-03-09 12:56:30.798 XXXXXX[562:307] 0.000000, 12.985626 <- bookmark
What happened to my Bookmark?
Bookmark.h
@interface Bookmark : NSManagedObject
{
}
@property (nonatomic, retain) NSDate * dateCreated;
@property (nonatomic, retain) NSString * longText;
@property (nonatomic, retain) NSString * shortText;
@property (nonatomic, retain) NSNumber * longitude;
@property (nonatomic, retain) NSNumber * latitude;
@end
Bookmark.m
#import "Bookmark.h"
@implementation Bookmark
@dynami开发者_Python百科c dateCreated;
@dynamic longText;
@dynamic shortText;
@dynamic longitude;
@dynamic latitude;
@end
Since everything seems to be fine from the code I suggest you take a look at managed object model. Probably entity with wrong data type? Also it could be that your NSLog
(or other logging statement) has wrong placeholder in format (like %f
instead of %@
, since property is NSNumber
object).
精彩评论