Skip to content

Commit

Permalink
Merge pull request #7 from p-x9/feature/do-not-export-default-value
Browse files Browse the repository at this point in the history
fix to not reflect default values to model
  • Loading branch information
p-x9 authored Dec 22, 2022
2 parents a779891 + 9684a3b commit d39d40b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sources/SDCALayer/Util/PropertyMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension PropertyMap {
extension PropertyMap {
/// IndirectlyCodable -> ObjectConvertiblyCodable
/// (IndirectlyCodable -> Codable)
@_disfavoredOverload
func apply<Target: AnyObject, Object: AnyObject>(to target: Target, from object: Object) where Key: PartialKeyPath<Object>, Value == ReferenceWritableKeyPathValueApplier<Target>, Target: ObjectConvertiblyCodable, Object: IndirectlyCodable {

self.forEach { keyPath, applier in
Expand All @@ -58,3 +59,32 @@ extension PropertyMap {
}
}
}

import QuartzCore
extension PropertyMap {
/// CALayer -> CALayerConvertible
/// (CaLayer -> Codable)
func apply<Target: AnyObject, Object: AnyObject>(to target: Target, from object: Object) where Key: PartialKeyPath<Object>, Value == ReferenceWritableKeyPathValueApplier<Target>, Target: ObjectConvertiblyCodable, Object: CALayer & IndirectlyCodable {

self.forEach { keyPath, applier in
var value = object[keyPath: keyPath]

switch value {
case let v as (any IndirectlyCodable):
guard let codable = v.codable() else { return }
value = codable

case let v as [any IndirectlyCodable]:
value = v.compactMap { $0.codable() }

default:
break
}

if let keyPath = keyPath._kvcKeyPathString,
object.shouldArchiveValue(forKey: keyPath) {
applier.apply(value, target)
}
}
}
}

0 comments on commit d39d40b

Please sign in to comment.