How can i store UIColor in CoreData without loss on 64 bit? On 32 bit the correct UIColor is returned.
CoreData setup
- attribute type: Transformable
- NSManagedObject subclass property: @NSManaged var color: UIColor?
Before the color value is stored
color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
output e.g. red on 64bit:
0.20000000000000018
output red on 32 bit
0.199999928
After the color is retrieved from CoreData
color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
output e.g. red on 64bit:
0.20000000298023224
output red on 32 bit:
0.199999928
Resulting Problem
Color comparison, using == , fails on 64 bit, because the values slightly differ. On 32 bit everything is fine and color comparison succeeds.
Swift 5.7, minimum deployment target iOS 11
Be aware, that Xcode complines in console:
'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
.