0

I used to make apps in swiftUI and now I'm making an app in UIKit with MVVM architecture.

In SwiftUI. There is a property wrapper called @EnviormentObject that allows you to access a class anywhere in the app.

I want to integrate a viewModel that is initialized in the SceneDelegate and can be accessed from anywhere in the app without needing to reinitialize the class.

An example would be to watch the current user and if its state changes to nil, present a notification to the user. But for that it needs to be a class that is only inited once so it doesn't have to load the data every time it is called.

How can I integrate a class that is inited in SceneDelegate and can be accessed from anywhere in the app?

Thanks.

1 Answers1

0

Don't use MVVM in UIKit, it's better to use child view controllers and the responder chain.

You can call a method in your view controller that will automatically work its way up to the scene delegate without needing to pass a reference down.

malhal
  • 26,330
  • 7
  • 115
  • 133