Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
robbieduncan said:
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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."
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
robbieduncan said:
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.