We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 37c8dfb commit 7b95406Copy full SHA for 7b95406
SwiftUI-Combine/ContentView.swift
@@ -14,6 +14,19 @@ class UserModel: ObservableObject {
14
@Published var password = ""
15
@Published var passwordAgain = ""
16
@Published var valid = false
17
+
18
+ private var cancellableSet: Set<AnyCancellable> = []
19
20
+ init() {
21
+ $userName
22
+ .debounce(for: 0.8, scheduler: RunLoop.main)
23
+ .removeDuplicates()
24
+ .map { input in
25
+ return input.count >= 3
26
+ }
27
+ .assign(to: \.valid, on: self)
28
+ .store(in: &cancellableSet)
29
30
}
31
32
struct ContentView: View {
@@ -39,7 +52,7 @@ struct ContentView: View {
39
52
40
53
41
54
42
-
55
43
56
struct ContentView_Previews: PreviewProvider {
44
57
static var previews: some View {
45
58
ContentView()
0 commit comments