views:

59

answers:

2

I can only guess, but please correct me if I am wrong:

[encoder encodeValueOfObjCType:@encode(NSDecimal) at:&theDecimal];

where encoder is an instance of NSCoder.

But one thing is strange: Why is there no key to provide? How would I get that back then, without a key?

+2  A: 

Again at the very top of NSDecimalNumber's documentation, it states that it conforms to the NSCoding protocol, which means you can put it into an NSCoder the normal way:

[encoder encodeObject:theDecimal forKey:@"aKey"];

Edit: Whoops, I see you meant NSDecimal, not NSDecimalNumber. My bad. Still, a very simple way would be to wrap the NSDecimal in an NSDecimalNumber and store it that way.

iKenndac
Wrapping it to NSDecimalNumber is a good idea. At this point I could live with the overhead.
HelloMoon
+1  A: 

The old non-keyed coding protocol requires you to extract the keys in the same order as you encoded them.

kaizer.se