Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-25-2011, 10:09 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 45
alextattoo is on a distinguished road
Default 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?
alextattoo is offline   Reply With Quote
Old 11-25-2011, 10:16 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Then convert your string into a decimal number. not got the code to hand and havnt done it for a while, but its possible to reformat your string as a number. that is the best option i believe for your problem.
Meredi86 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
16 members and 384 guests
chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, LunarMoon, Murphy, QuantumDoja, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0