From c250769620e7c0c1c48cbf2627c78c2e18c53319 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 24 Jan 2020 13:20:02 -0500 Subject: [PATCH] using existing model encoding func --- .../Molecules/Items/CarouselItemModel.swift | 4 ++++ .../Items/DropDownFilterTableViewCell.swift | 17 +++-------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift index 726d4846..4f4c3b58 100644 --- a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift +++ b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift @@ -14,8 +14,10 @@ import Foundation public var backgroundColor: Color? public var peakingUI: Bool? public var peakingArrowColor: Color? + public var moleculeName: String? private enum CodingKeys: String, CodingKey { + case moleculeName case backgroundColor case peakingUI case peakingArrowColor @@ -24,6 +26,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) @@ -33,6 +36,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(peakingUI, forKey: .peakingUI) try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift index ed2294a5..46139a37 100644 --- a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -32,21 +32,10 @@ import UIKit guard newValue != oldValue, let self = self, let index = self.dropDown.pickerData.firstIndex(of: newValue), - let molecules = self.dropDownListItemModel?.molecules + let dropListItemJSON = self.dropDownListItemModel.toJSON(), + let json2d = dropListItemJSON.optionalArrayForKey("molecules") as? [[[AnyHashable: Any]]] else { return } - - var json2d = [[[AnyHashable: Any]]]() - - for moleculeList in molecules { - var json1d = [[AnyHashable: Any]]() - for molecule in moleculeList { - if let moleculeDictionary = (molecule as? ListItemModel)?.toJSON() { - json1d.append(moleculeDictionary) - } - } - json2d.append(json1d) - } - + if self.previousIndex != NSNotFound { self.delegateObject?.moleculeDelegate?.removeMolecules(json2d[self.previousIndex], sender: self, animation: .fade) }