vds_ios/VDS/Protocols/SelectorGroupModelable.swift
Matt Bruce e07f855eb6 added Identifiable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-09-15 13:56:58 -05:00

38 lines
1.1 KiB
Swift

//
// 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 }
}
extension SelectorGroupModelable {
public var debugDescription: String {
"group id: \(id.uuidString)\r\(selectors.compactMap{"id: \($0.debugDescription) \($0.selected ? "*" : "")"}.joined(separator: "\r"))"
}
}
///MARK: Groups that allow single selections
public protocol SelectorGroupSelectedModelable: SelectorGroupModelable {
var selectedModel: SelectorModelType? { get }
}
extension SelectorGroupSelectedModelable {
public var selectedModel: SelectorModelType? {
if let index = selectors.firstIndex(where: { element in
return element.selected == true
}) {
return selectors[index]
} else {
return nil
}
}
}