Core data sum and show result in tableview
Hi, my app have 3 tabBars, in the first tab user enter data (3 digits round numbers only no float) in UITextField and save it. Same data is showed in TableView of second tab ,so i want the last row of the table to show the sum of all entered numbers,my problem is that in my entity the corresponding attribute "price" is set as string if i set it as decimal or double i get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "price"; desired type = NSDecimalNumber; given type = NSCFString; value = 100.'
This is part of my saveData function:
NSLog(@"saveData");
[self dismissKeyboard];
Earnings *earn = (Earnings *)[NSEntityDescription insertNewObjectForEntityForName:@"Earnings" inManagedObjectContext:managedObjectContext];
earn.price =priceField.text; <<<<<<---------- ERROR HERE
earn.date = dateField.text;
earn.descriptio = descriptionField.text;
NSError *error;
if (![managedObjectContext save:&error])
{
NSLog(@"Problem saving: %@", [error localizedDescription]);
}
I know i have to convert string to double or decimal and convert it back in the second tab so it can be showed in the table view as result , i tried it but no success . Any help?
|