p-x9/indirectlycodable
Protocol for indirect `Codable`(`Encodable`, `Decodable`) conformance
Document
IndirectlyCodable
Target
Direct Codable conforming type aliases. Must conform to IndirectlyCodableModel described below.
typealias Target = CALayerModelcodable()
Get a Codable object.
codableTypeName
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)
}IndirectlyCodableModel
Target
Alias of the type to be represented
typealias Target = CALayerapplyProperties to Target
Apply 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)
}
}reverseApplyProperties with Target
Apply values from the target object to its own properties.
Licenses
Package Metadata
Repository: p-x9/indirectlycodable
Default branch: main
README: README.md