Here is my code that I would like to reorganize:
let myCell = MyCustomTableViewCell()
self.createCell(myCell, reuseIdentifierString: "myCellIdentifier")
MyCustomTableViewCell conforms to the SetCell protocol, so it works great. and SetCell protocol is not @obj_c protocol. This is a quick protocol.
private func createCell<T where T:SetCell>(classType: T, reuseIdentifierString: String) -> UITableViewCell {
var cell = _tableView.dequeueReusableCellWithIdentifier(reuseIdentifierString) as T
cell.setText()
return cell.getCustomCell()
}
And now I am reorganizing my code, I would like to create myCell depending on String, but the string is exactly the same as the name of my class. I do not want to use else-if or switch-case
let myCell: AnyClass! = NSClassFromString("MyCustomTableViewCell")
self.createCell(myCell, reuseIdentifierString: "myCellIdentifier")
But now myCell, which is AnyClass, is not protocol compliant. How can i do this?
David source
share