@objc protocol IValidatable : class { varisValid: Bool { get } }
import UIKit @objc protocol IValidationManager : class { func verificated() } @objc protocol IValidatable : class { var isValid: Bool { get } } class DSValidationManager : UIControl, IValidationManager { @IBOutlet var verifiedControls: [UIControl]? @IBOutlet var managedControls: [UIControl]? private (set) var valid : Bool = false { didSet { self.sendActions(for: .valueChanged) } } overrideinit(frame: CGRect) { super.init(frame: frame) self.verificated() } required init?(coder: NSCoder) { super.init(coder: coder) self.verificated() } func verificated() { self.checkVerifiedControls() self.controlsAction() } private func checkVerifiedControls() { guard let list:[IValidatable] = self.verifiedControls?.filter({$0 isIValidatable}) as? [IValidatable] else { return } self.valid = list.filter({!$0.isValid}).count==0 } private func controls Action() { guard let list = self.managedControls else { return } for item in list { item.isEnabled = self.valid } } }
var isValid: Bool { return self.text.verification(self.expression, required:self.valueRequired) } @IBOutlet var validateDelegates: [IValidationManager]? private func handleDelegateAction(_ sender: UITextField) { guard let list = self.validateDelegates else { return } for validateDelegate in list { validateDelegate.verificated() } }