diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 59bcbbd4..bd89d8fa 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -184,16 +184,6 @@ public class RadioSwatchGroupBase ModelHandlerType.ModelType? { - if let index = model.selectors.firstIndex(where: { element in - return element.inputId == viewModel.inputId - }) { - return model.selectors[index] - } else { - return nil - } - } - //-------------------------------------------------- // MARK: - UICollectionViewDelegateFlowLayout //-------------------------------------------------- diff --git a/VDS/Protocols/SelectorGroupModelHandlerable.swift b/VDS/Protocols/SelectorGroupModelHandlerable.swift index a67b94cd..06b7f5ac 100644 --- a/VDS/Protocols/SelectorGroupModelHandlerable.swift +++ b/VDS/Protocols/SelectorGroupModelHandlerable.swift @@ -105,18 +105,20 @@ extension SelectorGroupSelectedModelHandlerable { public func didSelect(_ selectedControl: ModelHandlerType) { //only changes local model in control, //this is now disconnected from the parent model - selectorViews.forEach { control in + for (index, control) in selectorViews.enumerated() { //only change the old and new if control == selectedControl { - if var cached = getCachedSelector(viewModel: control.model) { - cached.selected = true - replace(viewModel: cached) + let updated = model.selectors[index].copyWith { + $0.selected = true } + model.selectors[index] = updated + } else if control.isSelected { - if var cached = getCachedSelector(viewModel: control.model) { - cached.selected = false - replace(viewModel: cached) + let updated = model.selectors[index].copyWith { + $0.selected = false } + model.selectors[index] = updated + } }