I have not used the new @Observable stuff yet, but I am pretty sure that @Environment is used in SwiftUI views, not in view models.
What happens if you add the categories view model as a regular property of the NotesViewModel class without any property wrappers?
@Observable
class NotesViewModel {
var notes: [Note] = []
var categoriesViewModel: CategoriesViewModel
func foo(){
/// Thread 1: Fatal error: No Observable object of type CategoriesViewModel found. A View.environmentObject(_:) for CategoriesViewModel may be missing as an ancestor of this view.
print(categoriesViewModel.categories.count)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: