IndirectlyCodable

main

indirectly `Codable` protocol
p-x9/IndirectlyCodable

IndirectlyCodable

Protocol for indirect Codable(Encodable, Decodable) conformance

Document

IndirectlyCodable

Target

Direct Codable conforming type aliases. Must conform to IndirectlyCodableModel described below.

typealias Target = CALayerModel

codable()

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 = CALayer

applyProperties 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

MIT License

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Oct 19 2024 20:46:02 GMT-0900 (Hawaii-Aleutian Daylight Time)