I am trying to implement a maps feature on my application. However to I would like the latitude and longitude be passed into the map from an object that is stored in core data. However I am having problem setting the initial value on the object when I start my application. I have tried 2 different ways so far and each and error I receive is "Sending 'double to a parameter of incompatible type 'id'. Any help would be very appreciated.
NSManagedObject *room = [NSEntityDescription insertNewObjectForEntityForName:@"Room" inManagedObjectContext:context];
double myLatitude = -1.228087;
double myLongitude = 52.764397;
[room setValue:@"H001" forKey:@"code"];
[room setValue:@"This is a description" forKey:@"roomDescription"];
[room setValue:myLatitude forKey:@"longitude"];
[room setValue:myLatitude forKey:@"latitude"];
NSManagedObject
attributes need to be objects, but double
is a primitive C type. The solution is to wrap the doubles in an NSNumber
:
[room setValue:[NSNumber numberWithDouble:myLongitude] forKey:@"longitude"];
[room setValue:[NSNumber numberWithDouble:myLatitude] forKey:@"latitude"];
You should wrap your double as an NSNumber:
[NSNumber numberWithDouble:myDouble]
NSManagedObject setValue:forKey: requires an id for it's value. The double is a primitive.
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