krzysztofzablocki / Inject

Hot Reloading for Swift applications!
MIT License
2.14k stars 114 forks source link

It doesn't seem to update UIHostingController #26

Closed antranapp closed 2 years ago

antranapp commented 2 years ago

I was trying to use Inject to update a SwiftUI View in a UIKit-based application, but it doesn't seem to work.

import UIKit
import SwiftUI
import Inject

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
    ) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        let viewController = UIViewController()
        viewController.view.backgroundColor = .white
        window?.rootViewController = UIHostingController(rootView: ContentView())
        window?.makeKeyAndVisible()

        #if DEBUG
        Bundle(path: "/Users/antran/Desktop/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
        #endif
        return true
    }

}

struct ContentView: View {
    var body: some View {
        Text("Hot Reloading")
            .enableInjection()
    }
}

https://user-images.githubusercontent.com/478757/163295293-28ff2639-05df-407f-a89f-af8375235bd3.mp4

Do you have any suggestion how to make this setup working?

antranapp commented 2 years ago

ah, I missed

@ObservedObject private var iO = Inject.observer

It's working now.