Sending float to parameter of incompatible type id

Alex Blair

I'm in the middle of creating a button that uses core data to save a name, xCoordinate, and yCoordinate of a point annotation. I can successfully persist the name, but I keep getting this error when I try to save a coordinate. I've logged the correct data, I just can't seem to save it.

When I try to setValue for the newPOI, I get an error that reads: Sending 'float' to parameter of incompatible type 'id'.

In the data model, the attribute is set to float. self.latitude and self.longitude are of type float.

My method is a little rough because I'm relatively new to this, but I would appreciate any feed back you could give me concerning the error. Below is my code for the method. I don't understand where 'id' comes into play here.

-(void) saveSelectedPoiName:(NSString *)name withY:(float)yCoordinate withX:(float)xCoordinate{
    self.pointFromMapView = [[MKPointAnnotation alloc] init];
    self.annotationTitleFromMapView = [[NSString alloc] init];

    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];

    self.annotationTitleFromMapView = name;
    self.latitude = yCoordinate;
    self.longitude = xCoordinate;

    NSEntityDescription *entityPOI = [NSEntityDescription entityForName:@"POI" inManagedObjectContext:context];
    NSManagedObject *newPoi = [[NSManagedObject alloc] initWithEntity:entityPOI insertIntoManagedObjectContext:context];
    //create new POI record
    [newPoi setValue:name forKey:@"name"];
    [newPoi setValue:yCoordinate forKey:@"yCoordinate"]; <---error happens here for yCoordinate.

    NSError *saveError = nil;

    if (![newPoi.managedObjectContext save:&saveError]) {
        NSLog(@"Unable to save managed object");
        NSLog(@"%@, %@", saveError, saveError.localizedDescription);
    }
}
Alex Blair

NSManagedObject attributes in Core Data must be an object and not of a primitive type. In this case our yCoordinate was of type float. In order to setValue: of a float type you must first wrap the value in an NSNumber.

[newPoi setValue:[NSNumber numberWithFloat:someFloat] forKey:@"yCoordinate"];

vs.

[newPoi setValue:someFloat forKey:@"yCoordinate"];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sending float to parameter of incompatible type id

From Dev

Error: Sending 'float[3]' to parameter of incompatible type 'float'

From Dev

Warning : "Sending 'NSObject *' to parameter of incompatible type 'id<NSCopying>'

From Dev

Sending AppController to parameter of incompatible type

From Dev

Xcode error: "passing 'float' to parameter of incompatible type id"

From Dev

Sending 'CGFloat' (aka 'float') to parameter incompatible type 'CGSize' (aka 'struct CGSize')

From Dev

Sending 'CGFloat' (aka 'float') to parameter incompatible type 'CGSize' (aka 'struct CGSize')

From Dev

Incompatible block pointer types sending 'int (^)(__strong id, __strong id)' to parameter of type 'NSComparator'

From Dev

Incompatible block pointer types sending 'int (^)(__strong id, __strong id)' to parameter of type 'NSComparator'

From Dev

How to completely hide the Xcode warning "Incompatible pointer to integer conversion sending 'id' to parameter of type (...)"?

From Dev

How to solve warning message: Sending 'viewController const __strong to parameter of incompatible type 'id<nsurlsessiondelegate>

From Dev

Incompatible pointer types sending 'const CFStringRef' (aka 'const struct __CFString *const') to parameter of type 'id'

From Dev

CUDA: argument of type float * is incompatible with parameter of type float (*)[32768]

From Dev

CUDA: argument of type "float" is incompatible with parameter of type "void *"

From Dev

Incompatible pointer to integer conversion sending 'NSNumber *' to parameter of type 'long'

From Dev

incompatible pointer types sending 'nsnumber *' to parameter of type 'nsstring *'

From Dev

Incompatible pointer types sending User* to parameter of type UserProfile*

From Dev

Incompatible with parameter of type "LPCWSTR"

From Dev

Incompatible Integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'NSInteger *' (aka 'int *')

From Dev

Thread 1:breakpoint 5.1: incompatible pointer types sending 'MWPhotoBrowser *' to parameter of type UIView

From Dev

Getter Setter : Incompatible Integer to pointer conversion sending 'int' to parameter of type 'int *'

From Dev

Incompatible pointer to integer conversion sending 'void *' to parameter of type 'PHImageContentMode' (aka 'enum PHImageContentMode')

From Dev

Passing void to a parameter of incompatible type?

From Dev

How to fix incompatible pointer type sending?

From Dev

How to fix incompatible pointer type sending?

From Dev

Incompatible pointer types passing retainable parameter of type 'float [2]'to a CF function expecting 'const CGFloat *' (aka 'const double *') type

From Dev

Argument of type "char *" is incompatible with parameter of type "LPWSTR"

From Dev

Argument of type "int" is incompatible with parameter of type "int *"

From Dev

argument of type "char *" is incompatible with parameter of type "LPCWSTR"

Related Related

  1. 1

    Sending float to parameter of incompatible type id

  2. 2

    Error: Sending 'float[3]' to parameter of incompatible type 'float'

  3. 3

    Warning : "Sending 'NSObject *' to parameter of incompatible type 'id<NSCopying>'

  4. 4

    Sending AppController to parameter of incompatible type

  5. 5

    Xcode error: "passing 'float' to parameter of incompatible type id"

  6. 6

    Sending 'CGFloat' (aka 'float') to parameter incompatible type 'CGSize' (aka 'struct CGSize')

  7. 7

    Sending 'CGFloat' (aka 'float') to parameter incompatible type 'CGSize' (aka 'struct CGSize')

  8. 8

    Incompatible block pointer types sending 'int (^)(__strong id, __strong id)' to parameter of type 'NSComparator'

  9. 9

    Incompatible block pointer types sending 'int (^)(__strong id, __strong id)' to parameter of type 'NSComparator'

  10. 10

    How to completely hide the Xcode warning "Incompatible pointer to integer conversion sending 'id' to parameter of type (...)"?

  11. 11

    How to solve warning message: Sending 'viewController const __strong to parameter of incompatible type 'id<nsurlsessiondelegate>

  12. 12

    Incompatible pointer types sending 'const CFStringRef' (aka 'const struct __CFString *const') to parameter of type 'id'

  13. 13

    CUDA: argument of type float * is incompatible with parameter of type float (*)[32768]

  14. 14

    CUDA: argument of type "float" is incompatible with parameter of type "void *"

  15. 15

    Incompatible pointer to integer conversion sending 'NSNumber *' to parameter of type 'long'

  16. 16

    incompatible pointer types sending 'nsnumber *' to parameter of type 'nsstring *'

  17. 17

    Incompatible pointer types sending User* to parameter of type UserProfile*

  18. 18

    Incompatible with parameter of type "LPCWSTR"

  19. 19

    Incompatible Integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'NSInteger *' (aka 'int *')

  20. 20

    Thread 1:breakpoint 5.1: incompatible pointer types sending 'MWPhotoBrowser *' to parameter of type UIView

  21. 21

    Getter Setter : Incompatible Integer to pointer conversion sending 'int' to parameter of type 'int *'

  22. 22

    Incompatible pointer to integer conversion sending 'void *' to parameter of type 'PHImageContentMode' (aka 'enum PHImageContentMode')

  23. 23

    Passing void to a parameter of incompatible type?

  24. 24

    How to fix incompatible pointer type sending?

  25. 25

    How to fix incompatible pointer type sending?

  26. 26

    Incompatible pointer types passing retainable parameter of type 'float [2]'to a CF function expecting 'const CGFloat *' (aka 'const double *') type

  27. 27

    Argument of type "char *" is incompatible with parameter of type "LPWSTR"

  28. 28

    Argument of type "int" is incompatible with parameter of type "int *"

  29. 29

    argument of type "char *" is incompatible with parameter of type "LPCWSTR"

HotTag

Archive