correction
This commit is contained in:
parent
874007423d
commit
dd7a339a43
@ -1,6 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
public enum MolecularError: Swift.Error {
|
||||
case error(String)
|
||||
case countImbalance(String)
|
||||
}
|
||||
|
||||
|
||||
public protocol MoleculeModelProtocol: ModelProtocol {
|
||||
var moleculeName: String { get }
|
||||
var backgroundColor: Color? { get set }
|
||||
|
||||
@ -29,10 +29,7 @@ import UIKit
|
||||
guard newValue != oldValue,
|
||||
let self = self,
|
||||
let index = self.dropDown.pickerData.firstIndex(of: newValue),
|
||||
let model = self.listItemModel as? DropDownListItemModel,
|
||||
let dropListItemJSON = (self.listItemModel as? DropDownListItemModel).toJSON(),
|
||||
let json2d = dropListItemJSON.optionalArrayForKey("molecules") as? [[[AnyHashable: Any]]],
|
||||
!json2d.isEmpty && !(json2d.first?.isEmpty ?? false)
|
||||
let model = self.listItemModel as? DropDownListItemModel
|
||||
else { return }
|
||||
|
||||
if self.previousIndex != NSNotFound {
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class DropDownListItemModel: ListItemModel, MoleculeModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -17,6 +18,10 @@ import Foundation
|
||||
public var molecules: [[ListItemModelProtocol & MoleculeModelProtocol]]
|
||||
public var dropDown: ItemDropdownEntryFieldModel
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Defaults to set
|
||||
public override func setDefaults() {
|
||||
super.setDefaults()
|
||||
@ -25,20 +30,24 @@ import Foundation
|
||||
style = "sectionFooter"
|
||||
}
|
||||
|
||||
// public func verify() throws {
|
||||
// guard dropDown.options.count != molecules.count else {
|
||||
// throw
|
||||
// }
|
||||
// }
|
||||
//--------------------------------------------------
|
||||
// MARK: - Functions
|
||||
//--------------------------------------------------
|
||||
|
||||
public class func verify(dropdown: ItemDropdownEntryFieldModel, molecules: [[ListItemModelProtocol & MoleculeModelProtocol]]) throws {
|
||||
guard dropdown.options.count == molecules.count else {
|
||||
throw MolecularError.countImbalance("dropdown.options.count is not equal to molecules.count")
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(molecules: [[ListItemModelProtocol & MoleculeModelProtocol]], dropDown: ItemDropdownEntryFieldModel) {
|
||||
public init(molecules: [[ListItemModelProtocol & MoleculeModelProtocol]], dropDown: ItemDropdownEntryFieldModel) throws {
|
||||
self.molecules = molecules
|
||||
self.dropDown = dropDown
|
||||
// try verify()
|
||||
try Self.verify(dropdown: dropDown, molecules: molecules)
|
||||
super.init()
|
||||
}
|
||||
|
||||
@ -60,6 +69,7 @@ import Foundation
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecules = try typeContainer.decodeModels2DIfPresent(codingKey: .molecules) ?? [[]]
|
||||
dropDown = try typeContainer.decode(ItemDropdownEntryFieldModel.self, forKey: .dropDown)
|
||||
try Self.verify(dropdown: dropDown, molecules: molecules)
|
||||
try super.init(from: decoder)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user