I am trying to save latitude and longitude in core data, but causing a bad access. here is the code:
EDIT :
Favourites *fav = (Favourites *)[NSEntityDescription insertNewObjectForEntityForName:@"Favourites" inManagedObjectContext:_managedObjectContext];
NSString *str = [NSString stringWithFormat:@"%@",point.title];
int index =[sharedRequest.name indexOfObject:str];
[fav setPlaceName:str];
double lat = [[sharedRequest.latArray objectAtIndex:index] doubleValue];
double lng = [[sharedRequest.lngArray objectAtIndex:index] doubleValue];
[fav setPlaceLatitude:lat];
[fav setPlaceLongitude:lng];
I don't know why this happening. Any help would be appreciable.
P.S lat and lng has value when I am printing them
You need to save your latitude and longitude value as a NSNumber instead of a double.
NSNumber *latitude = [NSNumber numberWithDouble:lat];
[fav setPlaceLatitude:latitude];
Update
For your Favorites entity, placeLatitude attribute should be a double. However, when using the NSManagedObject subclass Favorites, you need to use NSNumber to set placeLatitude. Core Data uses NSNumber to store primitives such as int, float, double, bool.
Let Xcode generate your Favorites class. Pick the Core Data data model on the left pane, then Xcode -> Editor -> Create NSManagedObject Subclass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With