I also has the same issue.... did you got any solution??
Post
Replies
Boosts
Views
Activity
hey it's actually quite easy you just have to override transformedValueClass() -> AnyClass as
override class func transformedValueClass() -> AnyClass {
return NSData.self
}
and then simply return NSData from transformedValue(_ value: Any?) -> Any? as shown below
override func transformedValue(_ value: Any?) -> Any? {
guard let color = value as? UIColor else { return nil }
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: color, requiringSecureCoding: true)
return data as NSData
} catch {
return nil
}
}
and while doing reverse transform you have to do one additional casting from NSData to Data then you good to go
override func reverseTransformedValue(_ value: Any?) -> Any? {
guard let nsData = value as? NSData else { return nil }
let data = nsData as Data
do {
let color = try NSKeyedUnarchiver.unarchivedObject(ofClass: UIColor.self, from: data)
return color
} catch {
return nil
}
}