30 lines
899 B
Swift
30 lines
899 B
Swift
//
|
|
// ModelTemplateProtocol.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Suresh, Kamlesh on 11/25/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
|
|
public protocol TemplateProtocol: FormHolderProtocol {
|
|
associatedtype TemplateModel: TemplateModelProtocol
|
|
var templateModel: TemplateModel? { get set }
|
|
}
|
|
|
|
public extension TemplateProtocol where Self: MFViewController {
|
|
func parseTemplateJSON() throws {
|
|
guard let pageJSON = self.loadObject?.pageJSON else { return }
|
|
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
|
let decoder = JSONDecoder()
|
|
let templateModel = try decoder.decode(TemplateModel.self, from: data)
|
|
|
|
if self.formValidator == nil, let rules = templateModel.formRules {
|
|
self.formValidator = FormValidator(rules)
|
|
}
|
|
self.templateModel = templateModel
|
|
}
|
|
}
|