I'm trying to save and get info about CAShapeLayers at .json files, using Codable protocol, but have an error:
public class Node: Codable {
public var name: String = ""
public var path: CGPath?
public var baseLayer: CAShapeLayer?
public required init(from decoder: Decoder) throws {
let container = try? decoder.container(keyedBy: NodeCodingKeys.self)
let _name = try container?.decodeIfPresent(String.self, forKey: NodeCodingKeys.name)
let _baseLayer = try container?.decodeIfPresent(CAShapeLayer.self, forKey: NodeCodingKeys.baseLayer)
name = _name ?? ""
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: NodeCodingKeys.self)
try container.encode(name, forKey: NodeCodingKeys.name)
}
}
public enum NodeCodingKeys: CodingKey {
case path
case name
case baseLayer
}
And the same for CGPath. Is there any way to save/receive them to/from device?