You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

2 years ago
2 years ago
2 years ago
  1. //
  2. // PrecompAsset.swift
  3. // lottie-swift
  4. //
  5. // Created by Brandon Withrow on 1/9/19.
  6. //
  7. import Foundation
  8. final class PrecompAsset: Asset {
  9. // MARK: Lifecycle
  10. required init(from decoder: Decoder) throws {
  11. let container = try decoder.container(keyedBy: PrecompAsset.CodingKeys.self)
  12. layers = try container.decode([LayerModel].self, ofFamily: LayerType.self, forKey: .layers)
  13. try super.init(from: decoder)
  14. }
  15. required init(dictionary: [String: Any]) throws {
  16. let layerDictionaries: [[String: Any]] = try dictionary.value(for: CodingKeys.layers)
  17. layers = try [LayerModel].fromDictionaries(layerDictionaries)
  18. try super.init(dictionary: dictionary)
  19. }
  20. // MARK: Internal
  21. enum CodingKeys: String, CodingKey {
  22. case layers
  23. }
  24. /// Layers of the precomp
  25. let layers: [LayerModel]
  26. override func encode(to encoder: Encoder) throws {
  27. try super.encode(to: encoder)
  28. var container = encoder.container(keyedBy: CodingKeys.self)
  29. try container.encode(layers, forKey: .layers)
  30. }
  31. }