Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 27, 2006, 05: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, 05: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, 05: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, 01: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, 01: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, 07: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

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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Parsing and inserting data into SQLITE - ios ashwinr87 iPhone/iPad Programming 1 Oct 31, 2011 07:46 AM
CoreData MultiThreading Delete ashwinr87 iPhone/iPad Programming 1 Oct 6, 2011 05:44 PM
MVC understanding and CoreData relationships between objects i.yalovecky Mac Programming 1 Mar 5, 2010 09:26 AM
NSOutlineView and CoreData problems Garrett Mac Programming 0 Jul 17, 2008 09:48 PM
Lame question about Cocoa and Coredata darksider Mac Programming 6 Feb 27, 2007 02:57 PM


All times are GMT -5. The time now is 12:19 AM.

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

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