I have a nib containing a bunch of UITableCellViews all derived from a class called MessageCell
. These custom classes are in Objective C and I have bridged them into my Swift project.
I'd like to be able to fetch one of interest. I tried this function
func cellTypeFromNib<T>(type : T) -> MessageCell? {
var cell : MessageCell? = nil
for obj in self.nibObjs {
if (obj is T) {
return obj as? MessageCell
}
}
return cell
}
and invoke it like this:
let cell = cellTypeFromNib(DerivedCell.self)?
This fails miserably. Stepping through the debugger, it looks like the objects in nibObjs
don't have the same type information as the metatype I've passed in.
I feel like this should be possible but I'm stumped.