I've multiple cells inherited from MyBaseCell class. In my ViewController class, I access those cells, type-cast them as MyBaseCell instance, and check if they respond to error label then assign error message to that label. It was easy using String literal in respondsToSelector
method.
Here is my existing code in ViewController class giving warning.
let cell = cell as? MyBaseCell
if cell?.respondsToSelector("errorLabel") == true {
let errorLabel = cell!.errorLabel as? UILabel
errorLabel?.text = "Some Error Message"
}
XCode 7.3 gives warning that No method declared with Objective-C selector 'errorLabel'. When I try changing it to respondsToSelector(#selector(MyBaseCell.errorLabel))
, it gives error 'Type MyBaseCell has no member errorLabel', which is true as errorLabel is in some of MyBaseCell's subclasses.
Here is my new code in ViewController class giving syntax error.
let cell = cell as? MyBaseCell
if cell?.respondsToSelector(#selector(MyBaseCell.errorLabel)) == true {
let errorLabel = cell!.errorLabel as? UILabel
errorLabel?.text = "Some Error Message"
}