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