Latest 1.2.1
Homepage https://github.com/jozsef-vesza/ViewModelExtensions
License MIT
Platforms ios 8.0, requires ARC
Frameworks Foundation, XCTest
Authors

Carthage compatible Version status license MIT

A convenience library to inject view models into view controllers defined in Interface Builder.

Usage

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:

  1. Currently nibs are not supported. Your view controllers must be defined in a storyboard file.
  2. The view controller’s storyboard ID must match the class name.

After these steps, you can initialize a view controller:

let exampleViewController = ExampleViewController.instanceWithViewModel(ExampleViewModel())

Installation

Carthage

github "jozsef-vesza/ViewModelExtensions"

CocoaPods

use_frameworks!

pod 'ViewModelExtensions'

Latest podspec

{
    "name": "ViewModelExtensions",
    "version": "1.2.1",
    "license": "MIT",
    "summary": "A convenience library to inject view models into view controllers defined in Interface Builder.",
    "homepage": "https://github.com/jozsef-vesza/ViewModelExtensions",
    "social_media_url": "https://twitter.com/j_vesza",
    "authors": {
        "Ju00f3zsef Vesza": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jozsef-vesza/ViewModelExtensions.git",
        "tag": "1.2.1"
    },
    "source_files": "**/*.swift",
    "platforms": {
        "ios": "8.0"
    },
    "frameworks": [
        "Foundation",
        "XCTest"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This