I have this wallet object that I use to do a lot in my app. I want to have a navigation from a login screen to go to here but every time it runs I get the tread 1: fatal error: No observableObject of type wallet found. I have an environmental object to the class call of type Wallet()
VStack{
headerView
ScrollView(.horizontal, showsIndicators: false){
HStack(spacing: 10){
ForEach(self.wallet.cards.indices, id:\
.self) { index in
CardView(card:
self.wallet.cards[index])
.onTapGesture {
self.wallet.cards.indices.forEach{ index in
self.wallet.cards[index].isSelected = false
}
self.wallet.cards[index].isSelected.toggle()
}
}
}
}
Spacer()
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello I am trying to connect a method from a class into a view but it is popping up with type '()' cannot conform to 'view'. The error is at the call to the showcard method in the scroll view. The second block of code is the class I am calling it from and the method I am using. Thank you
VStack{
headerView
ScrollView(.horizontal, showsIndicators: false){
HStack(spacing: 10){
viewModel.showCard()
}
}
Spacer()
}
}
@MainActor class ViewModel: ObservableObject{
@EnvironmentObject var wallet: Wallet
func showCard() {
ForEach(wallet.cards.indices, id:\
.self) { index in
CardView(card:
self.wallet.cards[index])
.onTapGesture {
self.wallet.cards.indices.forEach{ index in
self.wallet.cards[index].isSelected = false
}
self.wallet.cards[index].isSelected.toggle()
}
}
}
}
}