iphone - Problems with Float on core-data -
the following code largely inspired example found on net seems work fine, core data entity called "contact" , property called "address" having attribute string, in xcdatamodel. saves data no problem. question : how need modify code ? in order make work after change attribute of property "address" string float in xcdatamodel.
coredatatestoneappdelegate *appdelegate = [[uiapplication sharedapplication] delegate]; nsmanagedobjectcontext *context = [appdelegate managedobjectcontext]; nsmanagedobject *newcontact; newcontact = [nsentitydescription insertnewobjectforentityforname:@"contacts" inmanagedobjectcontext:context]; [newcontact setvalue:address_inputfield.text forkey:@"address"]; nserror *error; [context save:&error];
to store float in core data float attribute, wrap in nsnumber object this:
[newcontact setvalue:[nsnumber numberwithfloat:floatvalue] forkey:@"address"];
Comments
Post a Comment