Latest 1.0.1
Homepage https://github.com/makesource/ViewModelBindable
License MIT
Platforms ios 8.0
Dependencies RxSwift
Authors

⚡️Super easy way to bind ViewModel

  1. typealias your ViewModel which you want to inject

    typealias ViewModel = DetailViewModel
  2. Inject viewModel

    let viewController = DetailViewController()
    let viewModel = DetailViewModel()
    viewController.viewModel = viewModel
  3. Just enjoy bindViewModel(_:), bindStyles()
    This will be called automatically!

Usages

Just confrom your UIView or UIViewController to ViewModelBindable!

ViewModelBindable offers two binding method bindViewModel(_:), bindStyles()

  • UIViewController
    
    class DetailViewController: UIViewController {
    var disposeBag = DisposeBag()
    ...
    }

extension DetailViewController: ViewModelBindable {
typealias ViewModel = DetailViewModel

// perform binding here
func bindViewModel(viewModel: ViewModel) {
}

// This method is optional
 // Implement if you need
func bindStyles() {
}
}

- **UIView**
```swift
class DetailView: UIView {
  var disposeBag = DisposeBag()
  ...
}

extension DetailView: ViewModelBindable {
  typealias ViewModel = DetailViewModel

  // perform binding here
  func bindViewModel(viewModel: ViewModel) {
  }

  // This method is optional
  // Implement if you need
  func bindStyles() {
  }
}

Features

ViewModelBindable serves two binding methods which was used in MVVM architecture.

bindViewModel()

Usage

bindViewModel() is used for binding between View and ViewModel.

When is it called?

Right after UIViewController’s viewDidLoad()

Right after UIView’s viewModel injection

It’s recommended to bind UIView’s viewModel in ViewController’s bindViewModel(_:) method

func bindViewModel(viewModel: ViewModel) {
  headerView.viewModel = viewModel
  footerView.viewModel = viewModel
}

You can initialize some stuffs in viewDidLoad / awakeFromNib to prepare binding if you use storyboard

bindStyles()

Usage

bindStyles() is used for styling your views. This method is optional. So implement it if you need.

  • If your app support localized text or images, then styling it in ‘bindStyles()’
  • If your app support theme-based design that depends on user setting
  • If your app does not use Storyboard

When is it called?

Right before UIViewController’s initial viewWillAppear(_:) call and each time traitCollectionDidChange(_:) call

Right before each time UIView’s traitCollectionDidChange(_:) call

Dependency

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

ViewModelBindable is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'ViewModelBindable'

Author

makesource, [email protected]

License

ViewModelBindable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ViewModelBindable",
    "version": "1.0.1",
    "summary": "Super easy way to bind ViewModel",
    "description": "ViewModelBindable supports easy ViewModel binding for MVVM architecture. ViewModelBindable will inject required method for binding into your ViewController & View life-cycle. Just enjoy it!",
    "homepage": "https://github.com/makesource/ViewModelBindable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "makesource": "[email protected]"
    },
    "source": {
        "git": "https://github.com/makesource/ViewModelBindable.git",
        "tag": "v1.0.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ViewModelBindable/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            ">= 4.0.0"
        ]
    }
}

Pin It on Pinterest

Share This