                 self.addConstraint(constraint)
             }
         }
-        return subcomponents
     }
 }
 


import Foundation

protocol Configurable {
    func setupWithStyle(style: [Appearance])
    func handleCustomStyle(style: [String: AnyObject])
}

protocol Composable {
    func compositeSubcomponents(components: [ComponentTarget], layout: Layout) -> [UIView: ComponentTarget]
}

extension Composable where Self: UIView {
    func compositeSubcomponents(components: [ComponentTarget], layout: Layout) -> [UIView: ComponentTarget] {

        var subcomponents: [UIView: ComponentTarget] = [:]
        // create subview
        var viewsDictionary = [String: UIView]()
        for component in components {
            if let nibName = component.nibName,
                let componentView = NSBundle.mainBundle().loadNibNamed(nibName, owner: nil, options: nil).first as? UIView {
                    viewsDictionary[component.name] = componentView
                    self.addSubview(componentView)

                    // Setup each component view with style which listed in configuration
                    componentView.context.componentView = componentView
                    componentView.context.isRoot = false

                    subcomponents[componentView] = component
            }
            // It seems to me that there is no way to init an instance from class in Swift, so we made it in ObjC
            else if let componentView = ComponentFactory.componentViewFromClass(component.targetClass) {
                viewsDictionary[component.name] = componentView
                self.addSubview(componentView)

                // Setup each component view with style which listed in configuration
                componentView.context.componentView = componentView
                componentView.context.isRoot = false

                subcomponents[componentView] = component
            }
        }

        // apply diff, update the part only if changed
        /*
        for case let subview as Configurable in self.subviews {
        subview.setupWithConfiguration(configuration)
        }
        */

        // Layout each component view with auto layout visual format language from configuration.
        for format in layout.formats {

//        
//    }

    // TODO: how to handle clean up for reuse
    final func cleanUpForReuse() {

        // do clean up
