BindViewControllerToView 0.2.2

BindViewControllerToView 0.2.2

LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2016
SPMSupports SPM

Maintained by Francisco Gonçalves.


Easily embed any ViewController in a Collection/Table View Cell.

Basic Usage

To take advantage of this library there are a few steps that you need to follow:


Start by creating a cell that extends from ViewControllerCollectionCell and parameterize it with the ViewController that you intend to present.

class MyCollectionCell: ViewControllerCollectionCell<ViewController> {
  override func instantiateViewController() -> ViewController? {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewC") as! ViewController
    return vc


Then register your cell.

override func viewDidLoad() {

    // Register cell classes
    self.collectionView!.registerClass(MyCollectionCell.self, forCellWithReuseIdentifier: reuseIdentifier)

And set the current view controller as parent view controller.

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)

    if let cell = cell as? MyCollectionCell {
      cell.parentViewController = self
      cell.viewController?.model = model[indexPath.item]

    return cell


As the main purpose of this library is to be used with UICollectionViewControllers or UITableViewControllers it provides already some base classes like ViewControllerCollectionCell and ViewControllerTableCell. But it can be used to bind any view to any view controller by making the desired view implement the BindableView protocol.


To run the example project, clone the repo, and run pod install from the Example directory first.


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

pod "BindViewControllerToView"


Francisco Gonçalves, @franciscocsg


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