Hello, 

  I have a need to manually encode and decode double values archived using a 
NSKeyedArchiver. I can't use encodeDouble/decodeDouble in this case because of 
truly terrible performance in some previous releases of Mac OS (not sure if 
that's still the case in 10.6).

This worked well so far on all kinds of platforms including the iPhone 3G and 
3GS. Values sent back and forth on the same and different platforms were 
correctly encoded/decoded every time. On the iPhone 4 the decoding crashes at 
the indicated location (according to the crash logs I have) and I have no idea 
why.

The the Mac code is 32bit and runs on Leopard and Snow Leopard.

- (void)encodeDouble:(double)value forKey:(NSString *)key withCoder:(NSCoder 
*)encoder
{
    NSSwappedDouble sd = NSSwapHostDoubleToLittle(value);
    [encoder encodeBytes:(const uint8_t *)&sd length:sizeof(NSSwappedDouble) 
forKey:key];
}

- (double)decodeDoubleForKey:(NSString *)key withCoder:(NSCoder *)decoder
{
    double result = 0.0;
    NSUInteger retsize;
    NSSwappedDouble *sd = (NSSwappedDouble *)[decoder decodeBytesForKey:key 
returnedLength:&retsize];
    if (retsize == sizeof(NSSwappedDouble)) {  // <=== crash
        result = NSSwapLittleDoubleToHost(*sd);
    }
    return result;
}

I'm sure this will be a humiliating exercise for me but I don't have the 
faintest clue what the problem might be and I could use some help. Thanks a lot 
for any insight.

Regards
Markus
--
__________________________________________
Markus Spoettl

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to