I'm trying to refactor some code I have and thought I'd be able to move some of the code from globally accessible enum into the ViewModel of the app.
However, when I try to access it from the View it doesn't seem to be accessible or even an option in the autocomplete.
I was wondering if there was a reason why this was the case and if there was something I was missing..
// view
struct MyView: View {
@StateObject var vm = MyViewModel()
var body: some View {
ForEach(vm.MyEnum.allCases, id: \.self) { item in
...
}
}
}
// view model
final class MyViewModel: ObservableObject {
enum MyEnum: String, CaseIterable {
case a, b, c
}
}
I seem to be able to access everything else in a View Model but when it comes to enums they are not. I tried reading about enums to see why, but most things I come across are mainly "how-to" but nothing deep diving why.