Михаил Капелько 11 miesięcy temu
rodzic
commit
8cd6dac189
3 zmienionych plików z 46 dodań i 0 usunięć
  1. +25
    -0
      src/SrcFmt.swift
  2. +5
    -0
      src/V.swift
  3. +16
    -0
      src/VM.swift

+ 25
- 0
src/SrcFmt.swift Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz