krzysztofzablocki / Inject

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

Sugar #5

Closed dDomovoj closed 2 years ago

dDomovoj commented 2 years ago

Hello! Maybe it would be even more handy if something like this existed?

#if SUPPORTS_INJECTION
import Inject
#endif
import UIKit

protocol Injectable { }

extension UIViewController: Injectable { }
extension Injectable where Self: UIViewController {

#if SUPPORTS_INJECTION
  var injected: Inject.ViewControllerHost<Self> { Inject.ViewControllerHost(self) }
#else
  var injected: Self { self }
#endif

}

extension UIView: Injectable { }
extension Injectable where Self: UIView {

#if SUPPORTS_INJECTION
  var injected: Inject.ViewHost<Self> { Inject.ViewHost(self) }
#else
  var injected: Self { self }
#endif

}
krzysztofzablocki commented 2 years ago

I appreciate the idea but the host role is to allow to re-create (it uses autoclosure) whole View / VC on the spot, that way you can change memory layouts etc as long as your initializer is stable, allowing for much more stable workflow.

Because of that this wouldn't really work in practice in majority of cases where I used hosting