krzysztofzablocki / Inject

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

InjectionIII connected but view doesn't reload #66

Closed Dominus666 closed 1 year ago

Dominus666 commented 1 year ago

Hi, I have issue with hot-reload. In terminal I have next message // 💉 InjectionIII connected /Users/mac/Documents/Developer/Barter(swift)/Barter(swift).xcodeproj 💉 Watching files under the directory /Users/mac/Documents/Developer/Barter(swift) // and after when I press "ctrl + s" I have next message // 💉 Compiling /Users/mac/Documents/Developer/Barter(swift)/Barter(swift)/Views/AuthViews/AuthView.swift 💉 Loading .dylib ... 💉 Interposed 3 function references. 💉 Injected type #1 'Barterswift.AuthView' 💉 Injected type #2 'Barterswift.AuthView_Previews' //

but simulator doesn't reload

johnno1962 commented 1 year ago

Hi, do you have an instance variable in your View initialised to the Inject.observer or an @ObserveInject variable to force the redraw?

Dominus666 commented 1 year ago

Hi, do you have an instance variable in your View initialised to the Inject.observer or an @ObserveInject variable to force the redraw?

did you mean this?

Screenshot 2023-01-25 at 10 12 01
johnno1962 commented 1 year ago

Yes, @ObserveInjection, sorry. And it's still not redrawing? Do you have an @ObserveInjection in the Layout() view? They don't cascade unfortunately. Otherwise, SwiftUI caches Layout unless something in its state changes.

Dominus666 commented 1 year ago

I use only one @ObserveInjection. views redraw only when I change ContentView

Dominus666 commented 1 year ago

it's redrawing only in view where I add @ObserveInjection

johnno1962 commented 1 year ago

Only views that contain an @ObserveInjection are redrawn automatically. The subview appearance is cached by SwiftUI unless you add a @ObserveInjection to the subview which lets it know if needs to redraw.

Dominus666 commented 1 year ago

ok, thank you, it's working. and when I add @observe, should I rebuild project? because I get error

johnno1962 commented 1 year ago

Yes, you always need to rebuild after adding an instance variable. By @ObserveInject, I meant @ObserveInjection.

Dominus666 commented 1 year ago

ty for the help