12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // KMBaseTextFieldPresenter.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2022/12/23.
- //
- import Cocoa
- class KMBaseTextFieldPresenter: NSObject {
- var model: KMBaseTextFieldModel = KMBaseTextFieldModel()
- var delegate: KMBaseTextFieldPresenterDelegate?
- func initPresenter(delegate: KMBaseTextFieldPresenterDelegate, model: KMBaseTextFieldModel) {
- self.delegate = delegate
- self.model = model
- if self.delegate != nil {
- self.delegate?.valueDidChange(presenter: self, model: self.model)
- }
- }
- }
- extension KMBaseTextFieldPresenter: KMBaseTextFieldPresenterProtocol {
- func changeValue(value: String) {
- let string = value.replacingOccurrences(of: model.specialChart, with: "")
- if model.onlyNumber {
- if model.isCanNull {
- if string == "" {
- self.model.value = ""
- } else {
- self.model.value = String(min(max(Int(string) ?? 0, model.minValue),model.maxValue))
- }
- } else {
- self.model.value = String(min(max(Int(string) ?? 0, model.minValue),model.maxValue))
- }
- } else {
- self.model.value = string
- }
- if self.delegate != nil {
- self.delegate?.valueDidChange(presenter: self, model: self.model)
- }
- }
- }
- protocol KMBaseTextFieldPresenterDelegate: AnyObject {
- func valueDidChange(presenter: KMBaseTextFieldPresenter, model: KMBaseTextFieldModel)
- }
- protocol KMBaseTextFieldPresenterProtocol: AnyObject {
- func changeValue(value: String)
- }
- protocol KMBaseTextFieldPresenterPrivate {}
|