I'm building an AutoCompletion view and would like to pass an object which contains the field to be autocompleted. Currently I have two different types which I need to autocomplete on an attribute of, both attributes are named the same. I've created a Protocol and am using that to build a generic view to accept it.
The problem I'm encountering is that the onReceive breaks the compile. Unfortunately I can't get an error message apart from 'Unable to infer complex closure return type...' but if I comment out the onReceive the error clears.
If I replace LocationNameAutoComplete in the struct with Address then it compiles and runs fine - but that means I can't use it with the other type FactorySite.
If I could see the actual error message regarding the onReceive it would be a start...
Is there a better approach to doing this?
Thanks
struct LocationNameTextField<T>: View where T: LocationNameAutoComplete {
@ObservedObject var address: T
var body: some View {
VStack {
TextField("", text: $address.location_name)
.onReceive(self.address.$location_name) { attr in
print("OK")
}
}
}
}
protocol LocationNameAutoComplete: ObservableObject {
var location_name: String {get set}
}
struct Address: LocationNameAutoComplete {
@Published var location_name: String
}
struct FactorySite: LocationNameAutoComplete {
@Published var location_name: String
}