Is it possible to implement the Encodable
and Decodable
properties for UIColor
When I try to add a Decodable
extension I get an error
extension UIColor : Decodable {
public required init(from decoder: Decoder) throws {
self.init(red: 1, green: 1, blue: 1, alpha: 1)
}
}
error: ColorStuff.playground:98:21: error: initializer requirement 'init(from:)' can only be satisfied by a
required
initializer in the definition of non-final class 'UIColor' public required init(from decoder: Decoder) throws {
Am I missing something obvious here?
I have no issues with the Encodable
extension - it seems its a Decodable
issue.
The error message implies to me that I cannot do this due to not having access to the UIColor
class definition
'required' initializer must be declared directly in class 'UIColor' (not in an extension)
– OedipusCodable
. Or perhaps write a wrapper for it. – Summerwood