Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created September 24, 2021 18:56
Show Gist options
  • Save dmytro-anokhin/b95a5b247971ee5dca546e82d608ac3b to your computer and use it in GitHub Desktop.
Save dmytro-anokhin/b95a5b247971ee5dca546e82d608ac3b to your computer and use it in GitHub Desktop.
struct ContentView: View {
@ObservedObject private var autocomplete = AutocompleteObject()
@State var input: String = ""
var body: some View {
VStack {
TextField("", text: $input)
.textFieldStyle(.roundedBorder)
.padding()
.onChange(of: input) { newValue in
autocomplete.autocomplete(input)
}
}
List(autocomplete.suggestions, id: \.self) { suggestion in
ZStack {
Text(suggestion)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.onTapGesture {
input = suggestion
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment