Setting a double attribute value in NSManagedObject

I am trying to implement the map function in my application. However, I would like the latitude and longitude to be transferred to the map from the object that is stored in the master data. However, when starting the application, there is a problem with setting the initial value of the object. I have tried 2 different methods so far, and each of them and the error I get is "Sending" to a double parameter of incompatible type "id". Any help would be greatly 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"]; 
+4
source share
3 answers

NSManagedObject attributes must be objects, but double is a primitive type C. The solution is to wrap the doubles in NSNumber :

 [room setValue:[NSNumber numberWithDouble:myLongitude] forKey:@"longitude"]; [room setValue:[NSNumber numberWithDouble:myLatitude] forKey:@"latitude"]; 
+12
source

You should wrap your double NSNumber:

 [NSNumber numberWithDouble:myDouble] 

NSManagedObject setValue: forKey: it requires an identifier. The double is primitive.

+2
source

This answer tells you how to store a float in Core Data. Here for double

 [room setValue:[NSNumber numberWithDouble:myLatitude] forKey:@"latitude"]; 
0
source

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


All Articles