@sha921 Thank you very much for your help. I still have got some problems. I implemented the code as you said, but unfortunately I still do not get any results when I try to search something. Furthermore I don't know how I can link the results to already existing views with NavigationLink. Could you help me once more?
Thanks! Here is my code:
let medicList = ["Acetylsalicylsäure",
"Amiodaron",
"Atropin",
"Butylscopolamin",
"Dimenhydrinat",
"Dimentinden",
"Epinephrin",
"Esketamin",
"Furosemid",
"Glucagon",
"Glucose",
"Glyceroltrinitrat",
"Heparin",
"Ibuprofen",
"Ipratropiumbromid",
"Lidocain",
"Midazolam",
"Naloxon",
"Paracetamol",
"Prednisolon",
"Salbutamol",
"Sauerstoff",
"Urapidil",
"Vollelektrolytlösung"]
@State private var searchText = ""
var body: some View {
NavigationView {
List (medicList, id: \.self) { medic in
NavigationLink {
Text(medic) //destination here
} label: {
Text(medic)
}
}
.navigationTitle("Medikamente")
}
.searchable(text: $searchText)
}
var searchResults: [String] {
if searchText.isEmpty {
return medicList
} else {
return medicList.filter { $0.contains(searchText) }
}
}
}