Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 27, 2006, 06:39 AM   #1
MrFusion
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
NumberFormatters and coredata

I found out that to get more advanced formatters for your numbers, you need to program it yourself, instead of using the formatter in IB.

However, when I do this, I get the following error:

Unacceptable type of value for attribute: property = "fo"; desired type = NSDecimalNumber; given type = NSCFNumber; value = foo

So the formatter gives back NSCFNumber, but coredata needs NSDecimalNumber. Is there some easy way to convert them or to tell the formatter it needs to give back a NSDecimalNumber, without much glue code?

thanks
a newbie to ooredata
MrFusion is offline   0 Reply With Quote
Old Jun 27, 2006, 06:42 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
NSDecimalNumber appears to be a subclass of NSNumber so you should be able to use it in place.

Instead of creating an NSNumber simply create an NSDecimalNumber using the exact same method.
robbieduncan is offline   0 Reply With Quote
Old Jun 27, 2006, 06:50 AM   #3
MrFusion
Thread Starter
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
Quote:
Originally Posted by robbieduncan
NSDecimalNumber appears to be a subclass of NSNumber so you should be able to use it in place.

Instead of creating an NSNumber simply create an NSDecimalNumber using the exact same method.
Well, I never create a NSNumber. I have a entity in coredata that is an "Decimal" type, which is hooked up through bindings to a textfield.
The only code I have is the following:
myFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[myFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[myFormatter setHasThousandSeparators:NO];
[myFormatter setNumberStyle:NSNumberFormatterScientificStyle];
[[myTextfield cell] setFormatter:myFormatter];
I needs this because the IB formatter (supports only 10.0 style behavior) doesn't allow scientific notation and such.

The problem is somewhere in the communication between the textfield/formatter and coredata.
MrFusion is offline   0 Reply With Quote
Old Jun 27, 2006, 02:24 PM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Hmm OK then. I'm still looking around the docs.

You line where you set 10.4 behaviour is redundant though. From the docs

"Number formatters you initialize with init adopt the v10.4 formatter behavior."
robbieduncan is offline   0 Reply With Quote
Old Jun 27, 2006, 02:29 PM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Looks like you might need a Value Transformer.

I'd hazard this this may be a bug in the formatter when not running in 10.0 compatibility mode.
robbieduncan is offline   0 Reply With Quote
Old Jun 28, 2006, 08:15 AM   #6
MrFusion
Thread Starter
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
Quote:
Originally Posted by robbieduncan
Hmm OK then. I'm still looking around the docs.

You line where you set 10.4 behaviour is redundant though. From the docs

"Number formatters you initialize with init adopt the v10.4 formatter behavior."
Ok. I'll delete that line then.
I solved it by setting the attribute to double (I thought I tried that before posting here) and changing the numberstyle for each field depending on the way I want it displayed.
At the same time I changed the name of the attribute from "version" to "myVersion". The xml file also has a version-value. This probably doesn't matter, though.
It works, and that's good enough for me.
MrFusion is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
coredata doesn't support iOS7 manga iPhone and iPod touch Apps 1 Sep 25, 2013 12:37 PM
unrecognized selector sent to instance with Coredata and Category of NSMangedObject roeik iPhone/iPad Programming 5 Sep 5, 2012 06:40 AM
Coredata has App base and text files as backend for syncing mraheel iPhone/iPad Programming 0 Aug 8, 2012 11:59 PM
AirPrint CoreData Advice? truehybridx iPhone/iPad Programming 1 Jun 17, 2012 10:50 PM

Forum Jump

All times are GMT -5. The time now is 04:15 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC