ios - Sending float to parameter of incompatible type id -
i'm in middle of creating button uses core data save name, xcoordinate, , ycoordinate of point annotation. can persist name, keep getting error when try save coordinate. i've logged correct data, can't seem save it.
when try setvalue newpoi, error reads: sending 'float' parameter of incompatible type 'id'.
in data model, attribute set float. self.latitude , self.longitude of type float.
my method little rough because i'm relatively new this, appreciate feed give me concerning error. below code method. don't understand 'id' comes 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 ycoordinate. nserror *saveerror = nil; if (![newpoi.managedobjectcontext save:&saveerror]) { nslog(@"unable save managed object"); nslog(@"%@, %@", saveerror, saveerror.localizeddescription); } }
nsmanagedobject attributes in core data must object , not of primitive type. in case our ycoordinate of type float. in order setvalue: of float type must first wrap value in nsnumber.
[newpoi setvalue:[nsnumber numberwithfloat:somefloat] forkey:@"ycoordinate"];
vs.
[newpoi setvalue:somefloat forkey:@"ycoordinate"];
Comments
Post a Comment