From 205c83c0972d101f772e718020bf0705d6f67c7e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 28 Oct 2019 14:47:42 -0400 Subject: [PATCH] intial draft --- MVMCoreUI.xcodeproj/project.pbxproj | 124 ++++++++++++++++-- MVMCoreUI/Atoms/Views/Label.swift | 9 -- .../MFViewController+Model.swift | 27 ++++ MVMCoreUI/BaseControllers/MFViewController.h | 6 + MVMCoreUI/BaseControllers/MFViewController.m | 3 +- MVMCoreUI/Models/AttributeModel.swift | 48 ------- MVMCoreUI/Models/BaseModel.swift | 63 --------- MVMCoreUI/Models/Decoder.swift | 45 +++++++ MVMCoreUI/Models/Encoder.swift | 27 ++++ MVMCoreUI/Models/Holder.swift | 16 +++ MVMCoreUI/Models/HolderManager.swift | 79 +++++++++++ MVMCoreUI/Models/JSON/JSON.swift | 10 ++ MVMCoreUI/Models/JSON/JSONValue.swift | 122 +++++++++++++++++ MVMCoreUI/Models/LabelModel.swift | 66 ---------- MVMCoreUI/Models/MoleculeHolder.swift | 13 ++ MVMCoreUI/Models/MoleculeProtocol.swift | 16 +++ .../Models/Molecules/ActionMapModel.swift | 19 +++ .../Models/Molecules/FormModelProtocol.swift | 15 +++ MVMCoreUI/Models/Molecules/HeaderModel.swift | 22 ++++ .../Models/Molecules/HeadlineBodyModel.swift | 21 +++ MVMCoreUI/Models/Molecules/LabelModel.swift | 21 +++ .../Models/Molecules/ListItemModel.swift | 22 ++++ .../Molecules/MoleculeStackItemModel.swift | 20 +++ .../Models/Molecules/MoleculeStackModel.swift | 22 ++++ .../Models/Molecules/SeperatorModel.swift | 20 +++ .../Models/Molecules/TextFieldModel.swift | 23 ++++ MVMCoreUI/Models/PageModel.swift | 18 +++ .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 7 + .../Molecules/ModelMoleculeViewProtocol.swift | 13 ++ .../Molecules/MoleculeViewProtocol.swift | 38 ++++++ MVMCoreUI/Molecules/StandardHeaderView.swift | 20 ++- ...MoleculeMappingObject+ModelExtension.swift | 40 ++++++ ...UIMoleculeMappingObject+ModelMapping.swift | 22 ++++ .../MVMCoreUIMoleculeMappingObject.h | 3 + .../MVMCoreUIMoleculeMappingObject.m | 3 +- .../Templates/MoleculeListTemplate.swift | 10 +- 36 files changed, 849 insertions(+), 204 deletions(-) create mode 100644 MVMCoreUI/BaseControllers/MFViewController+Model.swift delete mode 100644 MVMCoreUI/Models/AttributeModel.swift delete mode 100644 MVMCoreUI/Models/BaseModel.swift create mode 100644 MVMCoreUI/Models/Decoder.swift create mode 100644 MVMCoreUI/Models/Encoder.swift create mode 100644 MVMCoreUI/Models/Holder.swift create mode 100644 MVMCoreUI/Models/HolderManager.swift create mode 100644 MVMCoreUI/Models/JSON/JSON.swift create mode 100644 MVMCoreUI/Models/JSON/JSONValue.swift delete mode 100644 MVMCoreUI/Models/LabelModel.swift create mode 100644 MVMCoreUI/Models/MoleculeHolder.swift create mode 100644 MVMCoreUI/Models/MoleculeProtocol.swift create mode 100644 MVMCoreUI/Models/Molecules/ActionMapModel.swift create mode 100644 MVMCoreUI/Models/Molecules/FormModelProtocol.swift create mode 100644 MVMCoreUI/Models/Molecules/HeaderModel.swift create mode 100644 MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift create mode 100644 MVMCoreUI/Models/Molecules/LabelModel.swift create mode 100644 MVMCoreUI/Models/Molecules/ListItemModel.swift create mode 100644 MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift create mode 100644 MVMCoreUI/Models/Molecules/MoleculeStackModel.swift create mode 100644 MVMCoreUI/Models/Molecules/SeperatorModel.swift create mode 100644 MVMCoreUI/Models/Molecules/TextFieldModel.swift create mode 100644 MVMCoreUI/Models/PageModel.swift create mode 100644 MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift create mode 100644 MVMCoreUI/Molecules/MoleculeViewProtocol.swift create mode 100644 MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift create mode 100644 MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 4c3b5900..376b136e 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -10,16 +10,37 @@ 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; - 01509D98232803C900EF99AA /* BaseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D97232803C900EF99AA /* BaseModel.swift */; }; - 01509D9A2328077C00EF99AA /* LabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D992328077C00EF99AA /* LabelModel.swift */; }; - 01509D9C23283F5000EF99AA /* AttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01509D9B23283F5000EF99AA /* AttributeModel.swift */; }; 016A1071228122180009D605 /* HeadlineBodyTextButtonSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A1070228122180009D605 /* HeadlineBodyTextButtonSwitch.swift */; }; + 017BEB3A2360EEB40024EF95 /* PageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB392360EEB40024EF95 /* PageModel.swift */; }; + 017BEB3C2361EA1D0024EF95 /* MFViewController+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */; }; + 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3F23620A230024EF95 /* TextFieldModel.swift */; }; + 017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */; }; + 017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */; }; + 017BEB48236230DB0024EF95 /* MoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */; }; + 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; }; + 017BEB7B236763000024EF95 /* SeperatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* SeperatorModel.swift */; }; + 017BEB7F23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */; }; 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; }; 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; + 01EB367923609281006832FA /* JSONValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB367723609281006832FA /* JSONValue.swift */; }; + 01EB367A23609281006832FA /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB367823609281006832FA /* JSON.swift */; }; + 01EB367D2360929F006832FA /* Decoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB367B2360929F006832FA /* Decoder.swift */; }; + 01EB367E2360929F006832FA /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB367C2360929F006832FA /* Encoder.swift */; }; + 01EB3681236092AE006832FA /* Holder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB367F236092AE006832FA /* Holder.swift */; }; + 01EB3682236092AE006832FA /* HolderManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB3680236092AE006832FA /* HolderManager.swift */; }; + 01EB3684236097C0006832FA /* MoleculeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB3683236097C0006832FA /* MoleculeProtocol.swift */; }; + 01EB3686236097F1006832FA /* MoleculeHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB3685236097F1006832FA /* MoleculeHolder.swift */; }; + 01EB368F23609801006832FA /* LabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368823609801006832FA /* LabelModel.swift */; }; + 01EB369023609801006832FA /* ListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368923609801006832FA /* ListItemModel.swift */; }; + 01EB369123609801006832FA /* MoleculeStackItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */; }; + 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368B23609801006832FA /* MoleculeStackModel.swift */; }; + 01EB369323609801006832FA /* HeaderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368C23609801006832FA /* HeaderModel.swift */; }; + 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368D23609801006832FA /* HeadlineBodyModel.swift */; }; + 01EB369523609801006832FA /* ActionMapModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368E23609801006832FA /* ActionMapModel.swift */; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; B8200E152280C4CF007245F4 /* ProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8200E142280C4CF007245F4 /* ProgressBar.swift */; }; @@ -199,15 +220,36 @@ 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = ""; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; - 01509D97232803C900EF99AA /* BaseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseModel.swift; sourceTree = ""; }; - 01509D992328077C00EF99AA /* LabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelModel.swift; sourceTree = ""; }; - 01509D9B23283F5000EF99AA /* AttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributeModel.swift; sourceTree = ""; }; 016A1070228122180009D605 /* HeadlineBodyTextButtonSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyTextButtonSwitch.swift; sourceTree = ""; }; + 017BEB392360EEB40024EF95 /* PageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageModel.swift; sourceTree = ""; }; + 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFViewController+Model.swift"; sourceTree = ""; }; + 017BEB3F23620A230024EF95 /* TextFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldModel.swift; sourceTree = ""; }; + 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormModelProtocol.swift; sourceTree = ""; }; + 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIMoleculeMappingObject+ModelExtension.swift"; sourceTree = ""; }; + 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeViewProtocol.swift; sourceTree = ""; }; + 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = ""; }; + 017BEB7A236763000024EF95 /* SeperatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeperatorModel.swift; sourceTree = ""; }; + 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIMoleculeMappingObject+ModelMapping.swift"; sourceTree = ""; }; 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = ""; }; 0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = ""; }; 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; + 01EB367723609281006832FA /* JSONValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONValue.swift; sourceTree = ""; }; + 01EB367823609281006832FA /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; + 01EB367B2360929F006832FA /* Decoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Decoder.swift; sourceTree = ""; }; + 01EB367C2360929F006832FA /* Encoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Encoder.swift; sourceTree = ""; }; + 01EB367F236092AE006832FA /* Holder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Holder.swift; sourceTree = ""; }; + 01EB3680236092AE006832FA /* HolderManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HolderManager.swift; sourceTree = ""; }; + 01EB3683236097C0006832FA /* MoleculeProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeProtocol.swift; sourceTree = ""; }; + 01EB3685236097F1006832FA /* MoleculeHolder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeHolder.swift; sourceTree = ""; }; + 01EB368823609801006832FA /* LabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelModel.swift; sourceTree = ""; }; + 01EB368923609801006832FA /* ListItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListItemModel.swift; sourceTree = ""; }; + 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackItemModel.swift; sourceTree = ""; }; + 01EB368B23609801006832FA /* MoleculeStackModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeStackModel.swift; sourceTree = ""; }; + 01EB368C23609801006832FA /* HeaderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderModel.swift; sourceTree = ""; }; + 01EB368D23609801006832FA /* HeadlineBodyModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeadlineBodyModel.swift; sourceTree = ""; }; + 01EB368E23609801006832FA /* ActionMapModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionMapModel.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; B8200E142280C4CF007245F4 /* ProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBar.swift; sourceTree = ""; }; @@ -403,9 +445,15 @@ 01509D96232803B200EF99AA /* Models */ = { isa = PBXGroup; children = ( - 01509D97232803C900EF99AA /* BaseModel.swift */, - 01509D992328077C00EF99AA /* LabelModel.swift */, - 01509D9B23283F5000EF99AA /* AttributeModel.swift */, + 017BEB392360EEB40024EF95 /* PageModel.swift */, + 01EB368723609801006832FA /* Molecules */, + 01EB3685236097F1006832FA /* MoleculeHolder.swift */, + 01EB3683236097C0006832FA /* MoleculeProtocol.swift */, + 01EB367F236092AE006832FA /* Holder.swift */, + 01EB3680236092AE006832FA /* HolderManager.swift */, + 01EB367B2360929F006832FA /* Decoder.swift */, + 01EB367C2360929F006832FA /* Encoder.swift */, + 01EB367623609281006832FA /* JSON */, ); path = Models; sourceTree = ""; @@ -421,6 +469,32 @@ path = FormUIHelpers; sourceTree = ""; }; + 01EB367623609281006832FA /* JSON */ = { + isa = PBXGroup; + children = ( + 01EB367723609281006832FA /* JSONValue.swift */, + 01EB367823609281006832FA /* JSON.swift */, + ); + path = JSON; + sourceTree = ""; + }; + 01EB368723609801006832FA /* Molecules */ = { + isa = PBXGroup; + children = ( + 01EB368823609801006832FA /* LabelModel.swift */, + 01EB368923609801006832FA /* ListItemModel.swift */, + 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */, + 01EB368B23609801006832FA /* MoleculeStackModel.swift */, + 01EB368C23609801006832FA /* HeaderModel.swift */, + 01EB368D23609801006832FA /* HeadlineBodyModel.swift */, + 01EB368E23609801006832FA /* ActionMapModel.swift */, + 017BEB3F23620A230024EF95 /* TextFieldModel.swift */, + 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */, + 017BEB7A236763000024EF95 /* SeperatorModel.swift */, + ); + path = Molecules; + sourceTree = ""; + }; D224798823142BF2003FCCF9 /* SwitchMolecules */ = { isa = PBXGroup; children = ( @@ -581,6 +655,8 @@ D274CA322236A78900B01B62 /* StandardFooterView.swift */, D29B770F22C281F400D6ACE0 /* ModuleMolecule.swift */, D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */, + 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */, + 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */, ); path = Molecules; sourceTree = ""; @@ -590,6 +666,7 @@ children = ( D29DF16021E69996003B2FB9 /* MFViewController.h */, D29DF15F21E69996003B2FB9 /* MFViewController.m */, + 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */, D29DF28F21E7ADB8003B2FB9 /* MFScrollingViewController.h */, D29DF29021E7ADB8003B2FB9 /* MFScrollingViewController.m */, D29DF29121E7ADB8003B2FB9 /* ProgrammaticScrollViewController.h */, @@ -796,6 +873,8 @@ D296E1402295EBBA0051EBE7 /* MoleculeDelegateProtocol.h */, D2A514562211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.h */, D2A514572211C53C00345BFB /* MVMCoreUIMoleculeMappingObject.m */, + 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */, + 017BEB7E23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -1022,45 +1101,56 @@ D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, + 017BEB48236230DB0024EF95 /* MoleculeViewProtocol.swift in Sources */, D2E1FADB2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift in Sources */, D27CD40E2322EEAF00C1DC07 /* TabsTableViewCell.swift in Sources */, D224799B231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift in Sources */, + 01EB3686236097F1006832FA /* MoleculeHolder.swift in Sources */, D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */, + 017BEB3C2361EA1D0024EF95 /* MFViewController+Model.swift in Sources */, D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, - 01509D9C23283F5000EF99AA /* AttributeModel.swift in Sources */, + 01EB3681236092AE006832FA /* Holder.swift in Sources */, D29DF12F21E6851E003B2FB9 /* MVMCoreUITopAlertMainView.m in Sources */, DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */, D224798C231450C8003FCCF9 /* HeadlineBodySwitch.swift in Sources */, + 017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */, D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, + 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, + 017BEB3A2360EEB40024EF95 /* PageModel.swift in Sources */, + 01EB367D2360929F006832FA /* Decoder.swift in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */, 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */, D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, + 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, + 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */, D29DF25421E6A177003B2FB9 /* MFMdnTextField.m in Sources */, B8200E152280C4CF007245F4 /* ProgressBar.swift in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, + 01EB369023609801006832FA /* ListItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, - 01509D98232803C900EF99AA /* BaseModel.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */, D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */, D29DF26D21E6AA0B003B2FB9 /* FLAnimatedImageView.m in Sources */, + 01EB367923609281006832FA /* JSONValue.swift in Sources */, D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, D22479942316AE5E003FCCF9 /* NSLayoutConstraintExtension.swift in Sources */, D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, + 01EB368F23609801006832FA /* LabelModel.swift in Sources */, 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, D22479962316AF6E003FCCF9 /* HeadlineBodyTextButton.swift in Sources */, D2E1FADD2268B25E00AEFD8C /* MoleculeTableViewCell.swift in Sources */, @@ -1068,6 +1158,8 @@ D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, + 017BEB7B236763000024EF95 /* SeperatorModel.swift in Sources */, + 017BEB7F23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift in Sources */, D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, @@ -1087,23 +1179,30 @@ DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */, D224798A2314445E003FCCF9 /* LabelSwitch.swift in Sources */, D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */, + 01EB367A23609281006832FA /* JSON.swift in Sources */, + 017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */, D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */, + 017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */, + 01EB3684236097C0006832FA /* MoleculeProtocol.swift in Sources */, D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */, D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */, 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */, D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */, D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, + 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, D2B1E3E522F37D6A0065F95C /* ImageHeadlineBody.swift in Sources */, D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */, 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */, + 01EB3682236092AE006832FA /* HolderManager.swift in Sources */, D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, - 01509D9A2328077C00EF99AA /* LabelModel.swift in Sources */, + 01EB369523609801006832FA /* ActionMapModel.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, + 01EB367E2360929F006832FA /* Encoder.swift in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, @@ -1111,6 +1210,7 @@ D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */, 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */, + 01EB369123609801006832FA /* MoleculeStackItemModel.swift in Sources */, D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */, D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */, D29DF32421ED0DA2003B2FB9 /* TextButtonView.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fcc3de4e..459b78cf 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -519,15 +519,6 @@ extension Label { @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { clauses = [] - - do { - let data = try JSONSerialization.data(withJSONObject: json!, options: .prettyPrinted) - let labelModel = try JSONDecoder().decode(LabelModel.self, from: data) - print("") - } catch let error { - print(error.localizedDescription) - } - Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData) originalAttributedString = attributedText } diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift new file mode 100644 index 00000000..05c9790d --- /dev/null +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -0,0 +1,27 @@ +// +// MFViewController+Model.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public extension MFViewController { + @objc func parsePageJSON() { + guard let pageJSON = loadObject?.pageJSON as? [String: AnyHashable] else { + return + } + do { + let pageData = try JSONSerialization.data(withJSONObject: pageJSON) + let decoder = JSONDecoder() + let pageModel = try decoder.decode(PageModel.self, from: pageData) + self.pageModel = pageModel + } catch { + print("error: \(error)") + } + + } +} diff --git a/MVMCoreUI/BaseControllers/MFViewController.h b/MVMCoreUI/BaseControllers/MFViewController.h index c1415df4..ded7446f 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.h +++ b/MVMCoreUI/BaseControllers/MFViewController.h @@ -29,16 +29,22 @@ #import #import + @class MainMenuViewController; @class MVMCoreUITabBarPageControlViewController; @class MVMAnimationManager; @class DelegateObject; +@class PageModel; @interface MFViewController : UIViewController // Stores the load object that this screen was loaded with. @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; +@property (nullable, strong, nonatomic) PageModel *pageModel; + +//@property (nonatomic) PageModel pageModel; + // The current selected text field. @property (nullable, weak, nonatomic) __block id selectedField; diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 256bf050..3b68ef7d 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -37,6 +37,7 @@ #import "MVMCoreUITabBarPageControlViewController.h" #import "MVMCoreUINavigationController.h" #import + @import MVMAnimationFramework; @interface MFViewController() @@ -95,7 +96,7 @@ - (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error { self.pageType = loadObject.pageType; self.loadObject = loadObject; - + [self parsePageJSON]; // Verifies all modules needed are loaded. return [MFViewController verifyRequiredModulesLoadedForLoadObject:loadObject error:error]; } diff --git a/MVMCoreUI/Models/AttributeModel.swift b/MVMCoreUI/Models/AttributeModel.swift deleted file mode 100644 index 426618e0..00000000 --- a/MVMCoreUI/Models/AttributeModel.swift +++ /dev/null @@ -1,48 +0,0 @@ -// -// AttributeModel.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 9/10/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -public class AttributeModel: BaseModel { - var type: String? - var location: Int? - var length: Int? - var textColor: String? - var size: Int? - var name: String? - - private enum CodingKeys : String, CodingKey { - case type - case location - case length - case textColor - case size - case name - } - - public required init(from decoder: Decoder) throws { - try super.init(from: decoder) - let container = try decoder.container(keyedBy: CodingKeys.self) - type = try container.decode(String.self, forKey: CodingKeys.type) - location = try container.decode(Int.self, forKey: CodingKeys.location) - length = try container.decode(Int.self, forKey: CodingKeys.length) - textColor = try container.decode(String.self, forKey: CodingKeys.textColor) - size = try container.decode(Int.self, forKey: CodingKeys.size) - name = try container.decode(String.self, forKey: CodingKeys.name) - } - - public override func encode(to encoder: Encoder) throws { - try super.encode(to: encoder) - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(type, forKey: .type) - try container.encode(location, forKey: .location) - try container.encode(textColor, forKey: .textColor) - try container.encode(size, forKey: .size) - try container.encode(name, forKey: .name) - } -} diff --git a/MVMCoreUI/Models/BaseModel.swift b/MVMCoreUI/Models/BaseModel.swift deleted file mode 100644 index 140833a5..00000000 --- a/MVMCoreUI/Models/BaseModel.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// BaseModel.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 9/10/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - - -public class BaseModel: Codable { - - public var moleculeName: String? - // public var dictionaryRepresentation: [AnyHashable: Any] - - private enum CodingKeys : String, CodingKey { - case moleculeName - } - - public required init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - moleculeName = try container.decode(String.self, forKey: CodingKeys.moleculeName) - } - - public func encode(to encoder: Encoder) throws { - //try super.encode(to: encoder) - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - } - -// //init -// public init(_ dictionary:[AnyHashable: Any]){ -// dictionaryRepresentation = dictionary -// } -// -// public func getString(_ key:String) -> String { -// return dictionaryRepresentation[key] as? String ?? "" -// } -// -// public func getOptionalString(_ key:String) -> String? { -// return dictionaryRepresentation[key] as? String ?? nil -// } -// -// public func dictionaryForKey(_ key : String) -> [String : Any]? { -// let dict = dictionaryRepresentation.dictionaryForKey(key) -// if dict.count > 0 { -// return dict -// } -// return nil -// } -// -// public func arrayForKey(_ key : String) -> Array>? { -// return dictionaryRepresentation.arrayForKey(key) as? Array> -// } -// -// public func convertStringToBool(_ string:String)-> Bool{ -// var converter = dictionaryRepresentation[string] as? String ?? "" -// converter = converter.lowercased() -// let convertedValue = converter == "true" || converter == "yes" -// return convertedValue -// } -} diff --git a/MVMCoreUI/Models/Decoder.swift b/MVMCoreUI/Models/Decoder.swift new file mode 100644 index 00000000..38fdc730 --- /dev/null +++ b/MVMCoreUI/Models/Decoder.swift @@ -0,0 +1,45 @@ +import Foundation + +public protocol AnyDecoder { + func decode(_ type: T.Type, from data: Data) throws -> T +} + +extension JSONDecoder: AnyDecoder {} +extension PropertyListDecoder: AnyDecoder {} + +extension Data { + public func decodeToObject(using decoder: AnyDecoder = JSONDecoder()) throws -> T { + return try decoder.decode(T.self, from: self) + } +} + +extension KeyedDecodingContainerProtocol { + public func decode(forKey key: Key) throws -> T { + return try decode(T.self, forKey: key) + } + + public func decode( + forKey key: Key, + default defaultExpression: @autoclosure () -> T + ) throws -> T { + return try decodeIfPresent(T.self, forKey: key) ?? defaultExpression() + } +} + +extension Decodable { + public static func decode(fileName: String, bundle: Bundle = Bundle.main) throws -> Self { + guard let path = bundle.path(forResource: fileName, ofType: ".json") else { + throw JSONError.pathNotFound + } + + guard let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path)) else { + throw JSONError.data(path: path) + } + + do { + return try jsonData.decode() + } catch { + throw JSONError.other(error: error) + } + } +} diff --git a/MVMCoreUI/Models/Encoder.swift b/MVMCoreUI/Models/Encoder.swift new file mode 100644 index 00000000..1f55038d --- /dev/null +++ b/MVMCoreUI/Models/Encoder.swift @@ -0,0 +1,27 @@ +import Foundation + +public protocol AnyEncoder { + func encode(_ value: T) throws -> Data +} + +extension JSONEncoder: AnyEncoder {} +extension PropertyListEncoder: AnyEncoder {} + +extension Encodable { + public func encodeToData(using encoder: AnyEncoder = JSONEncoder()) throws -> Data { + return try encoder.encode(self) + } + + public func toJSON() -> JSONObject? { + guard let data = try? self.encode() else { return nil } + return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONObject } + } + + public func toJSONString() -> String? { + guard let data = try? self.encode(), + let string = String(data: data, encoding: .utf8) else { + return nil + } + return string + } +} diff --git a/MVMCoreUI/Models/Holder.swift b/MVMCoreUI/Models/Holder.swift new file mode 100644 index 00000000..c8ae3f1f --- /dev/null +++ b/MVMCoreUI/Models/Holder.swift @@ -0,0 +1,16 @@ +import Foundation + +public protocol Holdable: Codable { + static var identifier: String { get set } +} + +public protocol Holder: Codable { + associatedtype HoldableType = Holdable + + static var codingKeyName: String { get } + + var name: String { get set } + var object: HoldableType { get set } + + init (name: String, object: HoldableType) +} diff --git a/MVMCoreUI/Models/HolderManager.swift b/MVMCoreUI/Models/HolderManager.swift new file mode 100644 index 00000000..44059145 --- /dev/null +++ b/MVMCoreUI/Models/HolderManager.swift @@ -0,0 +1,79 @@ +import Foundation + +public class HolderManager { + public enum Error: Swift.Error { + case codingKeyNotFound + case encoderError + case decoderError + case decoderErrorModelNotMapped + } + fileprivate typealias HoldableDecoder = (SingleValueDecodingContainer) throws -> Holdable + fileprivate typealias HoldableEncoder = (Holdable, inout SingleValueEncodingContainer) throws -> Void + fileprivate static var decoders: [String: HoldableDecoder] = [:] + fileprivate static var encoders: [String: HoldableEncoder] = [:] + + public static func register(_ type: A.Type) { + decoders[A.identifier] = { container in + try container.decode(A.self) + } + + encoders[A.identifier] = { name, container in + guard let obj = name as? A else { + throw HolderManager.Error.encoderError + } + try container.encode(obj) + } + } +} + +private struct DynamicKey: CodingKey { + var stringValue: String + init?(stringValue: String) { + self.stringValue = stringValue + } + + var intValue: Int? { return nil } + init?(intValue: Int) { return nil } +} + +//MARK: - Holder Extension +extension Holder { + + public init(from decoder: Decoder) throws { + + //get the CodingKey String name that tells the type of holdable + guard let key = DynamicKey(stringValue: Self.codingKeyName) else { + throw HolderManager.Error.decoderError + } + + //get the type + let typeContainer = try decoder.container(keyedBy: DynamicKey.self) + let type = try typeContainer.decode(String.self, forKey: key) + + //get the container to decode + let container = try decoder.singleValueContainer() + + //get the decoder for the type found + guard let decoder = HolderManager.decoders[type] else { + throw HolderManager.Error.decoderErrorModelNotMapped + } + + //decode the type and ensure it is of HoldableType + guard let obj = try decoder(container) as? HoldableType else { + throw HolderManager.Error.decoderError + } + + //instantiate Self + self = Self(name: type, object: obj) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + guard let encode = HolderManager.encoders[self.name], + let holdable = self.object as? Holdable else{ + throw HolderManager.Error.encoderError + } + try encode(holdable, &container) + } +} + diff --git a/MVMCoreUI/Models/JSON/JSON.swift b/MVMCoreUI/Models/JSON/JSON.swift new file mode 100644 index 00000000..cf584557 --- /dev/null +++ b/MVMCoreUI/Models/JSON/JSON.swift @@ -0,0 +1,10 @@ +import Foundation + +public typealias JSONArray = [[String: Any]] +public typealias JSONObject = [String: Any] + +public enum JSONError: Error { + case pathNotFound + case data(path: String) + case other(error: Error) +} diff --git a/MVMCoreUI/Models/JSON/JSONValue.swift b/MVMCoreUI/Models/JSON/JSONValue.swift new file mode 100644 index 00000000..2b51a255 --- /dev/null +++ b/MVMCoreUI/Models/JSON/JSONValue.swift @@ -0,0 +1,122 @@ +import Foundation + +public typealias JSONValueArray = [[String: JSONValue]] +public typealias JSONValueObject = [String: JSONValue] + +public enum JSONValueError: Error { + case encode +} + +extension Optional { + func or(_ other: Optional) -> Optional { + switch self { + case .none: return other + case .some: return self + } + } + + func resolve(with error: @autoclosure () -> Error) throws -> Wrapped { + switch self { + case .none: throw error() + case .some(let wrapped): return wrapped + } + } +} + +public enum JSONValue: Codable, Equatable { + case string(String) + case int(Int) + case double(Double) + case bool(Bool) + case object([String: JSONValue]) + case array([JSONValue]) + case null + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let value = ((try? container.decode(String.self)).map(JSONValue.string)) + .or((try? container.decode(Int.self)).map(JSONValue.int)) + .or((try? container.decode(Double.self)).map(JSONValue.double)) + .or((try? container.decode(Bool.self)).map(JSONValue.bool)) + .or((try? container.decode([String: JSONValue].self)).map(JSONValue.object)) + .or((try? container.decode([JSONValue].self)).map(JSONValue.array)) + + self = value ?? JSONValue.null + } + + func decode() throws -> T { + let encoded = try JSONEncoder().encode(self) + return try JSONDecoder().decode(T.self, from: encoded) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + switch self { + case .string(let string): try container.encode(string) + case .int(let int): try container.encode(int) + case .double(let double): try container.encode(double) + case .bool(let bool): try container.encode(bool) + case .object(let object): try container.encode(object) + case .array(let array): try container.encode(array) + case .null: break + } + } +} + +public func ==(lhs: JSONValue, rhs: JSONValue) -> Bool { + let ld = try? lhs.encode() + let rd = try? lhs.encode() + return ld == rd +} + +extension JSONValue: ExpressibleByStringLiteral { + public init(stringLiteral value: String) { + self = .string(value) + } +} + +extension JSONValue: ExpressibleByIntegerLiteral { + public init(integerLiteral value: Int) { + self = .int(value) + } +} + +extension JSONValue: ExpressibleByFloatLiteral { + public init(floatLiteral value: Double) { + self = .double(value) + } +} + +extension JSONValue: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self = .bool(value) + } +} + +extension JSONValue: ExpressibleByArrayLiteral { + public init(arrayLiteral elements: JSONValue...) { + self = .array(elements) + } +} + +extension JSONValue: ExpressibleByDictionaryLiteral { + public init(dictionaryLiteral elements: (String, JSONValue)...) { + self = .object([String: JSONValue](uniqueKeysWithValues: elements)) + } +} + +extension Dictionary where Key == String, Value == Any { + public func toJSONValue() throws -> [String:JSONValue] { + let data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) + return try JSONDecoder().decode([String:JSONValue].self, from: data) + } +} + +extension Dictionary where Key == String, Value == JSONValue { + public func toJSONObject() throws -> JSONObject{ + let encoded = try JSONEncoder().encode(self) + guard let json = try JSONSerialization.jsonObject(with: encoded, options: .mutableContainers) as? JSONObject else { + throw JSONValueError.encode + } + return json + } +} diff --git a/MVMCoreUI/Models/LabelModel.swift b/MVMCoreUI/Models/LabelModel.swift deleted file mode 100644 index 5aa7fffa..00000000 --- a/MVMCoreUI/Models/LabelModel.swift +++ /dev/null @@ -1,66 +0,0 @@ -// -// LabelModel.swift -// MVMCoreUI -// -// Created by Suresh, Kamlesh on 9/10/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -class LabelModel: BaseModel { - - var text: String - var accessibilityText: String - var textColor: String - var backgroundColor: String - var fontStyle: String - var fontName: String - var fontSize: Int - var textAlignment: String - //var attributes: AttributeModel - var html: String - - private enum CodingKeys : String, CodingKey { - case text - case accessibilityText - case textColor - case backgroundColor - case fontStyle - case fontName - case fontSize - case textAlignment - //case attributes - case html - } - - public required init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - text = try container.decode(String.self, forKey: CodingKeys.text) - accessibilityText = try container.decode(String.self, forKey: CodingKeys.accessibilityText) - textColor = try container.decode(String.self, forKey: CodingKeys.textColor) - backgroundColor = try container.decode(String.self, forKey: CodingKeys.backgroundColor) - fontStyle = try container.decode(String.self, forKey: CodingKeys.backgroundColor) - fontName = try container.decode(String.self, forKey: CodingKeys.fontName) - textAlignment = try container.decode(String.self, forKey: CodingKeys.textAlignment) - //attributes = try container.decode(AttributeModel.self, forKey: CodingKeys.attributes) - html = try container.decode(String.self, forKey: CodingKeys.html) - fontSize = try container.decode(Int.self, forKey: CodingKeys.fontSize) - try super.init(from: decoder) - } - - public override func encode(to encoder: Encoder) throws { - try super.encode(to: encoder) - var container = encoder.container(keyedBy: CodingKeys.self) - - try container.encode(text, forKey: .text) - try container.encode(accessibilityText, forKey: .accessibilityText) - try container.encode(textColor, forKey: .textColor) - try container.encode(backgroundColor, forKey: .backgroundColor) - try container.encode(fontStyle, forKey: .fontStyle) - try container.encode(fontName, forKey: .fontName) - try container.encode(textAlignment, forKey: .textAlignment) - //try container.encode(attributes, forKey: .attributes) - try container.encode(html, forKey: .html) - } -} diff --git a/MVMCoreUI/Models/MoleculeHolder.swift b/MVMCoreUI/Models/MoleculeHolder.swift new file mode 100644 index 00000000..e83889c2 --- /dev/null +++ b/MVMCoreUI/Models/MoleculeHolder.swift @@ -0,0 +1,13 @@ +import Foundation + +public class MoleculeHolder: Holder { + public static var codingKeyName: String = "moleculeName" + + public var name: String + public var object: MoleculeProtocol + + required public init(name: String, object: MoleculeProtocol) { + self.name = name + self.object = object + } +} diff --git a/MVMCoreUI/Models/MoleculeProtocol.swift b/MVMCoreUI/Models/MoleculeProtocol.swift new file mode 100644 index 00000000..4dcdce60 --- /dev/null +++ b/MVMCoreUI/Models/MoleculeProtocol.swift @@ -0,0 +1,16 @@ +import Foundation + +public protocol MoleculeProtocol: Holdable { + var moleculeName: String? {get} + var dictionary: [AnyHashable: Any]? {get} +} + +extension MoleculeProtocol { + public var moleculeName: String? { + get { return Self.identifier } + } + + public var dictionary: [AnyHashable: Any]? { + return toJSON() + } +} diff --git a/MVMCoreUI/Models/Molecules/ActionMapModel.swift b/MVMCoreUI/Models/Molecules/ActionMapModel.swift new file mode 100644 index 00000000..8e2cc133 --- /dev/null +++ b/MVMCoreUI/Models/Molecules/ActionMapModel.swift @@ -0,0 +1,19 @@ +// +// ActionMap.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class ActionMapModel: Codable { + public var actionType: String? + public var pageType: String? + + public init(actionType: String?, pageType: String?){ + self.actionType = actionType + self.pageType = pageType + } +} diff --git a/MVMCoreUI/Models/Molecules/FormModelProtocol.swift b/MVMCoreUI/Models/Molecules/FormModelProtocol.swift new file mode 100644 index 00000000..7d31912a --- /dev/null +++ b/MVMCoreUI/Models/Molecules/FormModelProtocol.swift @@ -0,0 +1,15 @@ +// +// FormModelProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol FormModelProtocol: Holdable { + var required: Bool? {get} + var fieldKey: String? {get} + var groupName: String? {get} +} diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift new file mode 100644 index 00000000..98c80e4e --- /dev/null +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -0,0 +1,22 @@ +// +// Header.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class HeaderModel: MoleculeProtocol { + public static var identifier: String = "header" + public var moleculeName: String? + public var molecule: MoleculeHolder? + public var seperator: MoleculeHolder? + + public init(molecule: MoleculeHolder?){ + self.molecule = molecule + self.moleculeName = Self.identifier + } +} + diff --git a/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift new file mode 100644 index 00000000..c80991ba --- /dev/null +++ b/MVMCoreUI/Models/Molecules/HeadlineBodyModel.swift @@ -0,0 +1,21 @@ +// +// HeadlineBody.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class HeadlineBodyModel: MoleculeProtocol { + public static var identifier: String = "headlineBody" + public var moleculeName: String? + public var headline: LabelModel? + + public init(headline: LabelModel?){ + self.headline = headline + self.moleculeName = Self.identifier + } +} + diff --git a/MVMCoreUI/Models/Molecules/LabelModel.swift b/MVMCoreUI/Models/Molecules/LabelModel.swift new file mode 100644 index 00000000..61fa9fda --- /dev/null +++ b/MVMCoreUI/Models/Molecules/LabelModel.swift @@ -0,0 +1,21 @@ +// +// Label.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + + +import Foundation + +@objcMembers public class LabelModel: MoleculeProtocol { + public static var identifier: String = "label" + public var moleculeName: String? + public var text: String? + + public init(text: String?) { + self.text = text + self.moleculeName = Self.identifier + } +} diff --git a/MVMCoreUI/Models/Molecules/ListItemModel.swift b/MVMCoreUI/Models/Molecules/ListItemModel.swift new file mode 100644 index 00000000..6b1ceade --- /dev/null +++ b/MVMCoreUI/Models/Molecules/ListItemModel.swift @@ -0,0 +1,22 @@ +// +// ListItem.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class ListItemModel: MoleculeProtocol { + public static var identifier: String = "listItem" + public var moleculeName: String? + public var molecule: MoleculeHolder? + public var actionMap: ActionMapModel? + + public init(molecule: MoleculeHolder?, actionMap: ActionMapModel?){ + self.molecule = molecule + self.actionMap = actionMap + self.moleculeName = Self.identifier + } +} diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift new file mode 100644 index 00000000..cb590493 --- /dev/null +++ b/MVMCoreUI/Models/Molecules/MoleculeStackItemModel.swift @@ -0,0 +1,20 @@ +// +// MoleculeStackItem.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/4/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class MoleculeStackItemModel: MoleculeProtocol { + public static var identifier: String = "moleculeStackItem" + public var moleculeName: String? + public var molecule: MoleculeHolder? + + public init(molecule: MoleculeHolder?){ + self.molecule = molecule + self.moleculeName = Self.identifier + } +} diff --git a/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift new file mode 100644 index 00000000..5dfda19c --- /dev/null +++ b/MVMCoreUI/Models/Molecules/MoleculeStackModel.swift @@ -0,0 +1,22 @@ +// +// MoleculeStack.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/3/19. +// Copyright © 2019 Suresh, Kamlesh. All rights reserved. +// + +import Foundation + +@objcMembers public class MoleculeStackModel: MoleculeProtocol{ + public static var identifier: String = "moleculeStack" + public var moleculeName: String? + public var molecules: [MoleculeStackItemModel]? + public var axis: String? + + public init(axis: String?, molecules: [MoleculeStackItemModel]?){ + self.axis = axis + self.molecules = molecules + self.moleculeName = Self.identifier + } +} diff --git a/MVMCoreUI/Models/Molecules/SeperatorModel.swift b/MVMCoreUI/Models/Molecules/SeperatorModel.swift new file mode 100644 index 00000000..f58f8da1 --- /dev/null +++ b/MVMCoreUI/Models/Molecules/SeperatorModel.swift @@ -0,0 +1,20 @@ +// +// SeperatorModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/28/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class SeperatorModel: MoleculeProtocol { + public static var identifier: String = "seperator" + public var moleculeName: String? + public var type: String? + + public init(type: String?) { + self.type = type + self.moleculeName = Self.identifier + } +} diff --git a/MVMCoreUI/Models/Molecules/TextFieldModel.swift b/MVMCoreUI/Models/Molecules/TextFieldModel.swift new file mode 100644 index 00000000..74e7cd3e --- /dev/null +++ b/MVMCoreUI/Models/Molecules/TextFieldModel.swift @@ -0,0 +1,23 @@ +// +// TextFieldModel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class TextFieldModel: MoleculeProtocol, FormModelProtocol { + public static var identifier: String = "textField" + + public var editable = true + public var errorMsg: String? + public var label: String? + public var type: String? + public var regex: String? + + public var required: Bool? + public var fieldKey: String? + public var groupName: String? +} diff --git a/MVMCoreUI/Models/PageModel.swift b/MVMCoreUI/Models/PageModel.swift new file mode 100644 index 00000000..b23cade8 --- /dev/null +++ b/MVMCoreUI/Models/PageModel.swift @@ -0,0 +1,18 @@ +// +// Page.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class PageModel: Codable { + public var template: String? + public var pageType: String? + public var screenHeading: String? + public var isAtomicTabs: Bool = false + public var header: HeaderModel? + public var molecules: [ListItemModel]? +} diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 4c69b1f7..af39df41 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -8,8 +8,10 @@ #import @import MVMCore.MVMCoreViewProtocol; +//@import MVMCoreUI.Swift; @class MVMCoreUIDelegateObject; @class MVMCoreErrorObject; +@class MoleculeProtocol; @protocol MVMCoreUIMoleculeViewProtocol @@ -18,6 +20,11 @@ @optional +// optional func setWithModel(_ model: MoleculeProtocol, _ delegateObject: MVMCoreUIDelegateObject, _ additionalData: [String: AnyHashable]) +//Type arguments cannot be applied to non-parameterized class 'NSObject' +//- (void)setWithModel:(nullable NSObject*)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; + + /// Called after init to provide an early setter for any molecule specific logic - (void)setAsMolecule; diff --git a/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift new file mode 100644 index 00000000..98c1818c --- /dev/null +++ b/MVMCoreUI/Molecules/ModelMoleculeViewProtocol.swift @@ -0,0 +1,13 @@ +// +// ModelMoleculeViewProtocol.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +public protocol ModelMoleculeViewProtocol { + func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) +} diff --git a/MVMCoreUI/Molecules/MoleculeViewProtocol.swift b/MVMCoreUI/Molecules/MoleculeViewProtocol.swift new file mode 100644 index 00000000..af1d09b4 --- /dev/null +++ b/MVMCoreUI/Molecules/MoleculeViewProtocol.swift @@ -0,0 +1,38 @@ +// +// MVMCoreUIMoleculeViewProtocol1.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +import UIKit +import MVMCore.MVMCoreViewProtocol +//@import MVMCoreUI.Swift; + +@objc public protocol MoleculeViewProtocol: MVMCoreViewProtocol { + + /// Sets up the ui based on the json + @objc func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) + + /// Called after init to provide an early setter for any molecule specific logic + @objc optional func setAsMolecule() + + + /// Resets to default state before set with json is called again. + @objc optional func reset() + + + /// For the molecule list to load more efficiently. + @objc optional static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat + + + /// Allows the molecule to set its name for reuse. Default could be moleculeName. + @objc optional static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? + + + /// Can return the required modules + @objc optional static func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? +} diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 12819313..4af65f2c 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -8,7 +8,8 @@ import UIKit -public class StandardHeaderView: ViewConstrainingView { +public class StandardHeaderView: ViewConstrainingView, ModelMoleculeViewProtocol { + var separatorView: SeparatorView? // MARK: - MVMCoreViewProtocol @@ -53,6 +54,23 @@ public class StandardHeaderView: ViewConstrainingView { separatorView?.setWithJSON(separatorJSON, delegateObject: delegateObject, additionalData: additionalData) } } + + open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { + //TODO: Need to create setWithModel in ViewConstraining View + super.setWithJSON(model?.toJSON(), delegateObject: delegateObject, additionalData: additionalData) + + // This molecule will by default handle margins. + (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false) + (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false) + + guard let headerModel = model as? HeaderModel else { + return + } + + if let seperatorModel = headerModel.seperator?.object as? SeperatorModel { + separatorView?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData) + } + } open override func reset() { super.reset() diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift new file mode 100644 index 00000000..1d3316fb --- /dev/null +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -0,0 +1,40 @@ +// +// MVMCoreUIMoleculeMappingObject+ModelExtension.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/24/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public extension MVMCoreUIMoleculeMappingObject { + + func createMolecule(_ model: MoleculeProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> (UIView & MVMCoreUIMoleculeViewProtocol)? { + return createMolecule(model, delegateObject, false) + } + + func createMolecule(_ model: MoleculeProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ constrainIfNeeded: Bool) -> (UIView & MVMCoreUIMoleculeViewProtocol)? { + guard let moleculeName = model.moleculeName, + let molecule = createMolecule(forName: moleculeName) as? MVMCoreUIViewConstrainingProtocol & UIView & MVMCoreUIMoleculeViewProtocol else { + return nil + } + + let setData = {() in + if let molecule = molecule as? ModelMoleculeViewProtocol { + molecule.setWithModel(model, delegateObject, nil) + } else { + molecule.setWithJSON(model.dictionary, delegateObject: delegateObject, additionalData: nil) + } + } + + if constrainIfNeeded, molecule.needsToBeConstrained?() ?? false { + let viewConstrainingView = ViewConstrainingView(molecule: molecule, alignment: molecule.alignment?() ?? .fill) + setData() + return viewConstrainingView + } + setData() + return molecule + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift new file mode 100644 index 00000000..c30c68d6 --- /dev/null +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift @@ -0,0 +1,22 @@ +// +// MVMCoreUIMoleculeMappingObject+ModelMapping.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 10/28/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objc public extension MVMCoreUIMoleculeMappingObject { + @objc static func registerObjects() { + HolderManager.register(LabelModel.self) + HolderManager.register(HeaderModel.self) + HolderManager.register(HeadlineBodyModel.self) + HolderManager.register(MoleculeStackModel.self) + HolderManager.register(ListItemModel.self) + HolderManager.register(MoleculeStackItemModel.self) + HolderManager.register(TextFieldModel.self) + HolderManager.register(SeperatorModel.self) + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h index 7d85a2ea..776566c8 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.h @@ -25,6 +25,9 @@ #pragma mark - Molecule Creation +/// Creates the molecule for the molecule name. +- (nullable UIView *)createMoleculeForName:(nonnull NSString *)name; + /// Creates the molecule for the molecule json. - (nullable UIView *)createMoleculeForJSON:(nonnull NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 945eb7bf..614251a9 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -17,6 +17,7 @@ #import "MVMCoreUIPageControl.h" #import "MVMCoreUIViewConstrainingProtocol.h" + @implementation MVMCoreUIMoleculeMappingObject - (NSMutableDictionary *)moleculeMapping { @@ -67,8 +68,8 @@ return mapping; } - + (nullable instancetype)sharedMappingObject { + [MVMCoreUIMoleculeMappingObject registerObjects]; return [MVMCoreActionUtility initializerClassCheck:[MVMCoreUIObject sharedInstance].moleculeMap classToVerify:self]; } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 0270cb63..3b1c31ef 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -27,9 +27,13 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { } open override func viewForTop() -> UIView { - guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), - let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return super.viewForTop() +// guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), +// let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { +// return super.viewForTop() +// } + guard let moleculeModel = pageModel?.header, + let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject() as? MVMCoreUIDelegateObject, true) else { + return super.viewForTop() } return molecule }