I am trying to move my @fetchrequest property to an auxiliar class, which is not a View
, but every time I try to do that, I get a bad instruction error.
Can anyone help me?
This is a sample of my code:
ViewModel:
class ViewModel {
@FetchRequest(entity: Teste.entity(), sortDescriptors: []) var teste: FetchedResults<Teste>
}
View:
struct ContentView: View {
let viewModel: ViewModel
init(viewModel: ViewModel) {
self.viewModel = viewModel
}
var body: some View {
List(viewModel.teste) { item in // error happens in this line
Text(item.id ?? "")
}
}
}
Thank you!