Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64-bit incompatibility between CGFloat and colorWithString #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

64-bit incompatibility between CGFloat and colorWithString #10

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented May 11, 2015

If you encode a UIColor on a 64-bit device with stringValue and then try to recreate it via colorWithString, the resulting RGB values will not be correct. This is because [NSScanner scanFloat] is trying to decode a double value. On 64-bit platforms CGFloat is a double and needs to be decoded using scanDouble.

Note: this fix only works for the case where the source and destination platforms are the same, e.g. if you're using it to save UIColors in NSDefaults on a single device. This solution will not work if the value may be encoded on one platform and decoded on a different one.

Note: I did not extensively test stringValue, but the format specifier is %f for 64-bit floating-point numbers (double) and the docs do not specify that this is different for 32-bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants