I can't implement a search bar, I would like to do a search among the device.make but both with the old search bar and with the new searchable implementation I don't know how to do it.
If I had a normal array there are no problems but in this case with this modelView I always get errors.
struct MedicalView: View {
init() {
modelView.getData()
}
@ObservedObject var modelView = DevicesViewModel()
@State var searchText = ""
@State private var showingAlert = false
var searchMake: [String] { // 1
if searchText.isEmpty {
return modelView.devices
} else {
return modelView.devices.filter { $0.localizedCaseInsensitiveContains(searchText) }
}
}
var body: some View {
NavigationView {
// ScrollView {
VStack {
List (modelView.devices) { device in
HStack {
VStack {
Text(device.make)
.font(.system(size: 20, weight: .heavy, design: .rounded))
Text(device.model)
.font(.system(size: 20, weight: .heavy, design: .rounded))
.foregroundColor(.white)
.shadow(color: .black, radius: 1)
Text(device.type)
.font(.system(size: 16, weight: .heavy, design: .rounded))
.foregroundColor(.blue)...
// .....
}
}
}
}.listStyle(.plain)
.searchable(text: $searchText)