Михаил Капелько 1 year ago
parent
commit
8cd6dac189
3 changed files with 46 additions and 0 deletions
  1. +25
    -0
      src/SrcFmt.swift
  2. +5
    -0
      src/V.swift
  3. +16
    -0
      src/VM.swift

+ 25
- 0
src/SrcFmt.swift View File

@@ -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<AnyObject?>?,
for string: String,
errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?
) -> 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
}
}

+ 5
- 0
src/V.swift View File

@@ -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()


+ 16
- 0
src/VM.swift View File

@@ -8,8 +8,24 @@ final class VM: ObservableObject {
@Published var t2 = "a:value"
var bt2: Binding<String>!
var subscriptions = Set<AnyCancellable>()
@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<String>(
get: { [weak self] in
String(self?.t2.dropFirst(2) ?? "")


Loading…
Cancel
Save