Once I make a search inside an array, I solely get the primary consequence somewhat than the consequence I looked for. As an illustration, there may be “John” and “Mary” within the searchingText.isEmpty half. Once I search Mary, I get John. Once I search John, I get John once more which is the primary title within the array. Something I ought to change in my code?
struct LikeInfo: View {
@ObservedObject var viewModel: PostViewModel
@State non-public var searchingText = ""
var searchResults: [String] {
return viewModel.announcement.likedName.filter { $0.comprises(searchingText) }
}
var physique: some View {
ScrollView{
if searchingText.isEmpty {
ForEach(0..<(viewModel.announcement.preferred.rely), id: .self) { i in
HStack {
Textual content(viewModel.announcement.likedName[i]
Spacer()
}
}
} else {
ForEach(0..<(searchResults.rely), id: .self) { i in VStack {
HStack {
Textual content(searchResults[i]
Spacer()
}
}
}
}
}
}
}