Skip to content

Commit

Permalink
Fix issue where SwiftUI wouldn't pick up state changes since they hap…
Browse files Browse the repository at this point in the history
…pened in the same runloop.
  • Loading branch information
jensutbult committed Sep 18, 2024
1 parent 1bf7177 commit 15ddbfb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Authenticator/Model/OATHPasswordViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ class OATHPasswordViewModel: ObservableObject {
self.isProcessing = true
self.state = .unknown
guard newPassword == repeatedPassword else {
self.state = .error(OATHViewModelError.passwordsDoNotMatch)
// Wait until the next runloop to change the state so SwiftUI picks it up
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
self.state = .error(OATHViewModelError.passwordsDoNotMatch)
}
return
}
connection.startConnection { connection in
Expand Down

0 comments on commit 15ddbfb

Please sign in to comment.