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