Post

Replies

Boosts

Views

Activity

Reply to hread 1: Fatal error: No ObservableObject of type Wallet found.
Here is the code in my main file. It links to the login view so that when the person logs in then it will take them to the content view that has all the other stuff including the code that I have posted before. //  idAppApp.swift //  idApp // // import SwiftUI @main struct idAppApp: App {     @StateObject private var wallet = Wallet()     var body: some Scene {         WindowGroup {             LoginView()         }     } } final class Wallet: ObservableObject {     @Published var cards = cardsData          var selectedCard: Card {         cards.first(where: { $0.isSelected})!     } }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’23
Reply to hread 1: Fatal error: No ObservableObject of type Wallet found.
Here is all of the code that I have in this file. I have an environmentObject for Wallet() and also added on for wallet but the Thread 1: Fatal error: No ObservableObject of type Wallet found error still shows up. Any help would be appreciated //  CardListView.swift //  idApp // //  // import SwiftUI struct CardListView: View {     @StateObject private var viewModel = ViewModel()     @EnvironmentObject var wallet: Wallet          var headerView: some View{         HStack{             Text("Healthcare cards")                 .font(.title2)                 .foregroundColor(Color(.black))                 .fontWeight(.bold)             Spacer()             Button("Add new card") {}                 .font(.callout)                 .foregroundColor(Color.primaryBlue)                 .padding(.trailing)         }     }          var body: some View {         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()         }         .environmentObject(wallet)     } } struct CardListView_Previews: PreviewProvider {     static var previews: some View {         CardListView()             .environmentObject(Wallet())     } }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’23