From 2ce25e340c44c18eccd177aa09a83192d3c9da12 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 9 Mar 2020 22:04:41 -0400 Subject: [PATCH] optimise --- MVMCoreUI/FormUIHelpers/FormValidator.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index ebc47f23..daadf81f 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -15,7 +15,7 @@ import MVMCore var extraValidationBlock: (() -> Bool)? var formRules: [FormGroupRule] var delegate: FormHolderProtocol? - var fieldMolecules: [FormFieldProtocol] = [] + var fieldMolecules: [String: FormFieldProtocol] = [:] var formActionMolecules: [FormActionFieldProtocol] = [] var radioButtonsModelByGroup: [String: RadioButtonSelectionHelper] = [:] @@ -24,9 +24,10 @@ import MVMCore } public func insertMolecule(_ molecule: FormItemProtocol) { - if var molecule = molecule as? FormFieldProtocol { + if var molecule = molecule as? FormFieldProtocol, + let fieldKey = molecule.fieldKey { molecule.baseValue = molecule.formFieldValue() - fieldMolecules.append(molecule) + fieldMolecules[fieldKey] = molecule } if let molecule = molecule as? FormActionFieldProtocol { formActionMolecules.append(molecule) @@ -68,7 +69,7 @@ import MVMCore } public func formField(for fieldKey: String) -> FormFieldProtocol? { - return fieldMolecules.first(where: { $0.fieldKey == fieldKey }) + return fieldMolecules[fieldKey] } } @@ -84,11 +85,10 @@ import MVMCore @objc func getFormParams( forGroup groupName: String) -> [String: Any] { var extraParam: [String: Any] = [:] MVMCoreDispatchUtility.performSyncBlock(onMainThread: { - for molecule in self.fieldMolecules { - if let formFieldName = molecule.fieldKey, - let formFieldValue = molecule.formFieldValue(), + for (fieldKey, molecule) in self.fieldMolecules { + if let formFieldValue = molecule.formFieldValue(), groupName == molecule.groupName { - extraParam[formFieldName] = formFieldValue + extraParam[fieldKey] = formFieldValue } } })