Friday, November 10, 2023
HomeiOS Developmentios - I can not perceive why I am getting this SwiftUI...

ios – I can not perceive why I am getting this SwiftUI Setting Object Error


So I am making an attempt to replace one property of an @EnvironmentObject. I preserve getting this error:

SwiftUI/EnvironmentObject.swift:90: Deadly error: No ObservableObject of kind ViewModel discovered. A View.environmentObject(_:) for ViewModel could also be lacking as an ancestor of this view.

My code appears to be like like this:

class HomeViewController: UIHostingController<HomeView> {
    
    // MARK: - Public Properties

    var topThreePublicUsers = PassthroughSubject<[ExternalUser], By no means>()

    
    // MARK: - Non-public Properties
    
    personal var cancellables: Set<AnyCancellable> = []
    
    
    // MARK: - Initializer
    
    init() {
        tremendous.init(rootView: HomeView())

        _ = rootView.environmentObject(HomeView.ViewModel())

        topThreePublicUsers
            .obtain(on: DispatchQueue.fundamental)
            .assign(to: .viewModel.topThreePublicUsers, on: rootView)
            .retailer(in:&cancellables)
    }
    
    @MainActor required dynamic init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been applied")
    }

    func pushPublicLeaderBoard(viewController: UIViewController) {
        if let viewController = viewController as? UIHostingController<PublicLeaderboardView> {
            rootView.viewModel.publicLeaderboard = viewController.rootView
        }
    }

}
struct HomeView: View {
    
    // MARK: - Setting
    
    @EnvironmentObject var viewModel: ViewModel

    
    // MARK: - View Mannequin
    
    class ViewModel: ObservableObject {
        @Revealed var profileView: ProfileView?
    }
      
    
    // MARK: - Physique
    
    var physique: some View {
        viewModel.profileView
    }
}

I am pondering I simply cannot entry the setting externally however I do not know… lil assist?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments