I have a SwiftUI List
which should both have a search bar and enable pull to refresh.
In theory, this is very simple. However, there is a search bar bug whenever I update any @Published
properties in the .refreshable { }
code.
My view looks like this:
struct MyView: View {
@State var text = ""
var body: some View {
NavigationView {
List {
Text("hello")
}
.refreshable {
model.prop = "world"
}
}
.searchable(text: $text)
}
}
And my model looks like this:
class Model: ObservableObject {
@Published var prop = ""
}
I've tried putting the update in an async block, but it did not solve the problem:
DispatchQueue.main.async {
model.prop = "world"
}
Any non-ObservableObject
-mutating code inside of the .refreshable { }
block works perfectly fine.
Am I doing something wrong?