To inject a ViewModel into a UIViewController using Swinject, follow the steps below:
Protocol for the ViewModel:main.swift88 chars4 linesClass for the ViewModel that confirms to the ViewModelProtocol:main.swift98 chars4 linesContainer instance and configure it to inject the ViewModelmain.swift104 chars6 linesUIViewController, create a private variable for the ViewModel and inject it using Swinject. This can be done using Constructor Injection:main.swift358 chars17 linesViewModel dependency and create an instance of the UIViewController using the init(viewModel:) initializer:main.swift79 chars2 linesAt this point, you have successfully injected the ViewModel into the UIViewController using Swinject.
gistlibby LogSnag