CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Sep 2015 |
| SPMSupports SPM | ✗ |
Maintained by József Vesza.
A convenience library to inject view models into view controllers defined in Interface Builder.
First, mark your classes as view models by conforming to the ViewModelType protocol.
struct ExampleViewModel: ViewModelType {
// Your implementation
}To support view model injection, your view controller class must conform to ViewControllerInitializable:
extension ExampleViewController: ViewControllerInitializable {
static func instanceWithViewModel(viewModel: ExampleViewModel) -> MainViewController? {
if let instance = self.instance() as? ExampleViewController {
instance.viewModel = viewModel
return instance
}
return nil
}
}Important:
After these steps, you can initialize a view controller:
let exampleViewController = ExampleViewController.instanceWithViewModel(ExampleViewModel())