@@ -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 | |||||
} | |||||
} |
@@ -10,6 +10,7 @@ struct V: View { | |||||
Text("'\(vm.text)'") | Text("'\(vm.text)'") | ||||
.fontWeight(.bold) | .fontWeight(.bold) | ||||
} | } | ||||
/* | |||||
TextField("Placeholder", text: $vm.text) | TextField("Placeholder", text: $vm.text) | ||||
.padding(8) | .padding(8) | ||||
.border(Color.red, width: 2) | .border(Color.red, width: 2) | ||||
@@ -17,6 +18,10 @@ struct V: View { | |||||
TextField("Binding-2", text: vm.bt2) | TextField("Binding-2", text: vm.bt2) | ||||
.padding(8) | .padding(8) | ||||
.border(Color.blue, width: 2) | .border(Color.blue, width: 2) | ||||
*/ | |||||
TextField("Binding-3", value: $vm.t3, formatter: SrcFmt()) | |||||
.padding(8) | |||||
.border(Color.green, width: 4) | |||||
} | } | ||||
.frame(width: 320) | .frame(width: 320) | ||||
.padding() | .padding() | ||||
@@ -8,8 +8,24 @@ final class VM: ObservableObject { | |||||
@Published var t2 = "a:value" | @Published var t2 = "a:value" | ||||
var bt2: Binding<String>! | var bt2: Binding<String>! | ||||
var subscriptions = Set<AnyCancellable>() | var subscriptions = Set<AnyCancellable>() | ||||
@Published var t3 = "a:value" | |||||
init() { | 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>( | bt2 = Binding<String>( | ||||
get: { [weak self] in | get: { [weak self] in | ||||
String(self?.t2.dropFirst(2) ?? "") | String(self?.t2.dropFirst(2) ?? "") | ||||