From 8cd6dac1891fef711f7505ae0ff53e042cf2b988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 15 Dec 2023 18:56:19 +0300 Subject: [PATCH] d --- src/SrcFmt.swift | 25 +++++++++++++++++++++++++ src/V.swift | 5 +++++ src/VM.swift | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/SrcFmt.swift diff --git a/src/SrcFmt.swift b/src/SrcFmt.swift new file mode 100644 index 0000000..dba75ad --- /dev/null +++ b/src/SrcFmt.swift @@ -0,0 +1,25 @@ +import Foundation + +class SrcFmt: Formatter { + override func string(for obj: Any?) -> String? { + /**/print("ИГР SrcF.string obj: '\(obj)'") + guard let str = obj as? String else { return nil } + return String(str.dropFirst(2)) + } + + override func getObjectValue( + _ obj: AutoreleasingUnsafeMutablePointer?, + for string: String, + errorDescription error: AutoreleasingUnsafeMutablePointer? + ) -> Bool { + /**/print("ИГР SrcF.getOV string: '\(string)'") + let val: String + if string.hasPrefix("a:") || string.hasPrefix("u:") { + val = string + } else { + val = "u:\(string)" + } + obj?.pointee = val as AnyObject + return true + } +} diff --git a/src/V.swift b/src/V.swift index 4011648..6e69e23 100644 --- a/src/V.swift +++ b/src/V.swift @@ -10,6 +10,7 @@ struct V: View { Text("'\(vm.text)'") .fontWeight(.bold) } + /* TextField("Placeholder", text: $vm.text) .padding(8) .border(Color.red, width: 2) @@ -17,6 +18,10 @@ struct V: View { TextField("Binding-2", text: vm.bt2) .padding(8) .border(Color.blue, width: 2) + */ + TextField("Binding-3", value: $vm.t3, formatter: SrcFmt()) + .padding(8) + .border(Color.green, width: 4) } .frame(width: 320) .padding() diff --git a/src/VM.swift b/src/VM.swift index d34d66d..c0fab10 100644 --- a/src/VM.swift +++ b/src/VM.swift @@ -8,8 +8,24 @@ final class VM: ObservableObject { @Published var t2 = "a:value" var bt2: Binding! var subscriptions = Set() + + @Published var t3 = "a:value" init() { + $t3 + //.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main) + .sink { v in + /**/print("ИГР VM.init t3: '\(v)'") + // Ignore repoting application initiated strings + // Only report user initiated strings + //guard v.hasPrefix("u:") else { return } + //Bus.Service.singleton?.send(MeetupId.Keys.meetupIdTextUI.rawValue, String(v.dropFirst(2))) + } + .store(in: &subscriptions) + + + + bt2 = Binding( get: { [weak self] in String(self?.t2.dropFirst(2) ?? "")