Hey, making the jump into SwiftUI and hit a hurdle. For my app home screen I want a struct to sift through various states and return the appropriate View based on a condition. In Swift I would usually apply some sort of Manager object to review the data states and return a class that inherits from UIView - but trying to do the same same in SwiftUI is causing me some problems - Example here:
Attempting to do this generates the error
Protocol 'View' can only be used as a generic constraint because it has Self or associated type requirements
on the -> View return type. From some research it looks like I could change this to some View and they wrap all my returns as AnyView but that feels like it's the wrong approach.
Any tips on how and why to handle this
Cheers!
Code Block struct HomeScreenViewDirector { func fetchView() -> View { if someDataState { return PopulatedHomeScreen() } else { return EmptyView() } } } struct EmptyHomeScreen: View { var body: some View { HStack { navigationBarTitle("Empty State") } } } struct PopulatedHomeScreen: View { var body: some View { navigationBarTitle("Populated State") } }
Attempting to do this generates the error
Protocol 'View' can only be used as a generic constraint because it has Self or associated type requirements
on the -> View return type. From some research it looks like I could change this to some View and they wrap all my returns as AnyView but that feels like it's the wrong approach.
Any tips on how and why to handle this
Cheers!