I am creating some reusable views, but to keep the question and example short, I am sharing limited code for now. Let's say I have created a CustomActionsView which displays the different messages and buttons in various styles as needed.
I created a view builder which returns the view based on different inputs. Sharing code below:
import SwiftUI
struct Destinations {
var messageText: String = ""
var viewStyle: Int = 0
@Binding var showingModal:Bool
enum CustomDestinations: Int, CaseIterable, Hashable {
case view1 = 0, view2 = 1, view3 = 2
@ViewBuilder var view: some View {
switch self {
case .view1: CustomActionsView(mainMessageText: self.messageText, viewStyle: 0, showingModal: self.$showingModal)
case .view2: CustomActionsView(mainMessageText: self.messageText, viewStyle: 1, showingModal: self.$showingModal)
case .view3: CustomActionsView(mainMessageText: self.messageText, viewStyle: 2, showingModal: self.$showingModal)
}
}
}
}
I have created a similar enum(not wrapped in struct) in other places in my app and it works fine since the view does not require any inputs. However in this case, CustomActionView expects messageText, viewStyle and a binding property, so I wrapped it within a struct thinking I can assign property values from struct and it will work.
But with this design I am getting the following error and similar error for other 2 properties too:
Value of type 'Destinations.CustomDestinations' has no member 'messageText'
I am not able to store properties within enum either.
Can we pass values to view's within enum?
Note: I am working on watch app with min watchOS version as 7.0.
Thanks!