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) ?? "")