This code works fine
ForEach(items.filter({$0.matchesSearch(text: searchText) }), id: \.id) { item in
but moving the collection out of the ForEach
let takenOut = items.filter({$0.matchesSearch(text: searchText) })
ForEach(takenOut, id: \.id) { item in
results in this error
Generic struct 'ForEach' requires that 'LazyFilterSequence<Results<T>>.SubSequence'
(aka 'LazyFilterSequence<Slice<Results<T>>>') conform to 'RandomAccessCollection'
any ideas why?
i need to take the sequence out so i can use it's count
whole code for the context
struct SearchSectionView<T: DatabaseItem & Identifiable & SearchMatchingSupport>: View {
@Binding var searchText: String
@ObservedResults(
T.self,
where: { $0.recordState == .published }
) var items
var body: some View {
Section("Results") {
let o = items.sorted(byKeyPath:"name", ascending: true).filter({$0.matchesSearch(text: searchText)})
ForEach(o, id: \.id) { item in
Label(item.suggestionText(), systemImage: "circle").searchCompletion("\(item.id)")
}
}
}
}




