// // SelectorGroupModel.swift // VDS // // Created by Matt Bruce on 8/11/22. // import Foundation ///MARK: Groups that allow anything selected public protocol SelectorGroupModelable: Modelable, FormFieldable { associatedtype SelectorModelType: Modelable where SelectorModelType: FormFieldable & Selectable var selectors: [SelectorModelType] { get set } } ///MARK: Groups that allow single selections public protocol SelectorGroupSelectedModelable: SelectorGroupModelable { var selectedInputId: String? { get set } var selectedModel: SelectorModelType? { get } } extension SelectorGroupSelectedModelable { public var selectedModel: SelectorModelType? { guard let selectedInputId else { return nil } if let index = selectors.firstIndex(where: { element in return element.inputId == selectedInputId }) { return selectors[index] } else { return nil } } }