views:

566

answers:

2

Hi,

I've got a Core Data managed object that has an attribute with a "Boolean" type.

In my header file I've got this: @property (nonatomic, retain) NSNumber * includeInHistory;

and I'm using a @dynamic includeInHistory implementation

When interacting with an instance of this managed object before saving to disk, I've got something that actually maps to a NSCFBoolean through the NSNumber interface. I'm using "json-framework" to encode some dictionary containing values coming from Core Data.

The problem is that after saving and retrieving the data back, includeInHistory returns what appears to be a standard NSNumber (integer, not typed as Boolean). This is problematic as when converted to JSON it maps to "includeInHistory" : 1 instead of includeInHistory" : true

For now, I've had to resort to unboxing, then reboxing everytime I'm about to export as JSON, but this seems like a bug to me.... Am I missing something here ?

Thanks

A: 

Sounds like the JSON Framework isn't recognizing that your number is of Boolean type. I would consider that a bug; I suggest you report it.

Peter Hosey
A: 

As far as Core Data is concerned a Boolean is just a NSNumber with its values limited to 0 or 1. Core Data expects the receiving controller and/or view code to display it properly.

However, since you are subclassing NSManagedObject anyway, then I would suggest writing a includeInHistoryValue methods that do the boxing and unboxing automatically. Then your JSON parser will deal with the primitive boolean instead.

You might also want to consider using mogenerator as that will add those boxing and unboxing methods and maintain your subclasses for you, automatically.

Marcus S. Zarra