Protocol for indirect Codable(Encodable, Decodable) conformance
Direct Codable conforming type aliases.
Must conform to IndirectlyCodableModel described below.
typealias Target = CALayerModelGet a Codable object.
When making a class conform to this protocol, it is not possible to create additional aliases to the Target type in the inherited class.
Therefore, you must use this property to get the class with NSClassFromString.
@objc
public class var codableTypeName: String {
String(reflecting: Target.self)
}Alias of the type to be represented
typealias Target = CALayerApply the value of a property of confidence to the target object. Using this library named p-x9/KeyPathValue, you can create a propertyMap as follows.
let propertyMap: [PartialKeyPath<CALayerModel>: ReferenceWritableKeyPathValueApplier<CALayer>] = [
\.bounds: .init(\.bounds),
\.position: .init(\.position),
\.frame: .init(\.frame),
\.backgroundColor: .init(\.backgroundColor),
\.cornerRadius: .init(\.cornerRadius),
\.borderWidth: .init(\.borderWidth),
\.borderColor: .init(\.borderColor)
]
func applyProperties(to target: CALayer) {
Self.propertyMap.forEach { keyPath, applier in
var value = self[keyPath: keyPath]
if let convertible = value as? (any IndirectlyCodableModel),
let converted = convertible.converted() {
value = converted
}
applier.apply(value, target)
}
}Apply values from the target object to its own properties.