I have a SwiftUI App which have a MainView and this is calling a sheet like
this:.sheet(isPresented: $showingSheetFilter) {
FilterView()
}
The FilterView looks like this:
import SwiftUI
struct FilterView: View {
@FetchRequest(
entity: Category.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \Category.title, ascending: true)
]
) var categories: FetchedResults<Category>
var body: some View {
List {
ForEach(categories, id: \.self) { (cat: Category) in
Text(cat.title!)
}
}.onAppear {
print(self.categories.count)
}
}
}
If I call the sheet I get an Dump:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
In the onAppear. If I remove the onAppear I get it in the ForEach.
Why this is happening?