AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
975 stars 75 forks source link

[Question] Injection in a @IBSegueAction function #240

Closed alphatroya closed 3 years ago

alphatroya commented 3 years ago

XCode 11 introduced @IBSegueAction as a new way for injection dependencies in VC modules. The new way suggests using new init(coder: ...) constructors. It broke up the current storyboard integration trick.

container.register(tag: "myVC") { 
      MyViewController() << not compile now as soon a new designated initializer now called
} 

Is there a way to use @Injected property wrappers or resolvingProperties callback in that case? Or maybe another workaround for using Storyboards alongside with IBSegueAction and Dip?

alphatroya commented 3 years ago

Resolved by using stub initializer

    init?(coder: NSCoder, dependency: String) {
        self.dependency = dependency
        super.init(coder: coder)
    }

    @available(*, unavailable)
    required init(coder _: NSCoder) {
        fatalError("NSCoding not supported")
    }

    convenience init() {
        fatalError("init should not be called directly")
    }