iOS Development

ios – I am unable to perceive why I am getting this SwiftUI Atmosphere Object Error

So I am making an attempt to replace one property of an @EnvironmentObject. I hold 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 seems 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())

            .obtain(on: DispatchQueue.important)
            .assign(to: .viewModel.topThreePublicUsers, on: rootView)
    @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: - Atmosphere
    @EnvironmentObject var viewModel: ViewModel

    // MARK: - View Mannequin
    class ViewModel: ObservableObject {
        @Printed var profileView: ProfileView?
    // MARK: - Physique
    var physique: some View {

I am considering I simply cannot entry the atmosphere externally however I do not know… lil assist?


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button