// // RadioButtonModel.swift // MVMCoreUI // // Created by Suresh, Kamlesh on 5/14/19. // Copyright © 2019 Verizon Wireless. All rights reserved. // import Foundation import UIKit @objcMembers public class RadioButtonModel: NSObject { private var selectedRadioButton: RadioButton? public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel? { guard let groupName = radioButton.groupName, let formValidator = formValidator else { return nil } let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel() formValidator.radioButtonsModelByGroup[groupName] = radioButtonModel return radioButtonModel } public func selected(_ radioButton: RadioButton) { selectedRadioButton?.radioButton.isSelected = false selectedRadioButton = radioButton selectedRadioButton?.radioButton.isSelected = true } } // MARK: - FormValidationProtocol extension RadioButtonModel: FormValidationProtocol { // Used to check the validity of the field, to enable/disable the primary button. @objc public func isValidField() -> Bool { return selectedRadioButton != nil ? true : false } // Name of the field to send to server @objc public func formFieldName() -> String? { return selectedRadioButton?.fieldKey } // The Feild value key value paid for sending to server @objc public func formFieldValue() -> Any? { return selectedRadioButton != nil ? true : false } }