What happens if a user running the 64-bit version of the app saves a file where these values are encoded as doubles and the file is opened/unarchived on a 32-bit system?
Nothing special. The file contains a double
, and presumably you're sending decodeDouble:forKey:
to retrieve the value, so you'll get a double
. You can then cast it to CGFloat
—which will lose precision if you're on a 32-bit machine, but you have to do that cast sooner or later. (Even if you hold onto the double
, you'll still have to cast to CGFloat
when you pass the value to Quartz/AppKit/UIKit.)
Consider the alternative: You store float
s in the file on a 64-bit machine, and then load the file back in on the same machine. You and Quartz can handle the full precision of the 64-bit double
type, but you don't have it, because you threw it away when you wrote out the file. If the value changed at all in the cast, that change is now permanent.
So my recommendation is to always use the double
type with NSKeyedArchiver, unless you know that you are never going to use anything but float
(i.e., the target API only uses float
, never double
). This isn't true of Quartz, so for CGFloat
, use double
.