Swiftpack.co - p-x9/IndirectlyCodable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by p-x9.
p-x9/IndirectlyCodable 0.1.0
indirectly `Codable` protocol
⭐️ 1
🕓 2 weeks ago
.package(url: "https://github.com/p-x9/IndirectlyCodable.git", from: "0.1.0")

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

GitHub

link
Stars: 1
Last commit: 2 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics