mercredi 29 juillet 2015

Swift reflection returning 0 on UITableViewCell

I have written a Binding Framework for automated binding between View and ViewModel based on name convention.

First I'm getting all the properties of the View and ViewModel by reflection:

  class func bind<T : IBoundableView , E : IBoundableViewModel>(view : T, viewModel : E) {
        var viewPropertyNameForValue = getPropertyValueForName(view)
        var viewModelPropertyNameForValue = getPropertyValueForName(viewModel)
        bindViewPropertiesToViewModel(viewPropertyNameForValue, viewModelPropertiesValueForName: viewModelPropertyNameForValue)
        viewModel.setBondableView(view)
    }


class func getPropertyValueForName<T>(viewModel : T)-> [String : Any] {

    let obj = viewModel
    let reflected = reflect(obj)
    var properties = [String : Any]()
    for index in 0..<reflected.count {
        properties[reflect(viewModel)[index].0] = reflected[index].1.value
    }
    return properties
}

Is works great on NSObject objects, and UIViewControllers, but when using UITableViewCell "getPropertyValueForName" returns 0.

So basically I'm looking for a way to use Reflection on UITableViewCell





Aucun commentaire:

Enregistrer un commentaire