Here is my code what I would like to refactor:
let myCell = MyCustomTableViewCell()
self.createCell(myCell, reuseIdentifierString: "myCellIdentifier")
the MyCustomTableViewCell conforms to the SetCell protocol so it works fine. and the SetCell protocol is not an @obj_c protocol. This is a swift 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 refactor my code, I would like to create the myCell depending on a String, but the string is exactly the same as my Class name. I dont want to use else-if or switch-case
let myCell: AnyClass! = NSClassFromString("MyCustomTableViewCell")
self.createCell(myCell, reuseIdentifierString: "myCellIdentifier")
But now the myCell which is AnyClass does not conform to protocol. How can I do this?