protocol Configurable {
}
class CoolConfiguration : Configurable {
}
class GenericTableViewCell<T: Configurable>: UITableViewCell {
}
class CoolTableViewCell : GenericTableViewCell<CoolConfiguration> {
init(aDecoder: NSCoder) {
/* The init() method doesn't work below...so no way to override
the init properly. Seems like this should work -- GenericTableViewCell is
_still_ a subclass of UITableViewCell, so what the heck?
*/
super.init(aDecoder)
/* Additionally if you look in CoolTableViewCell.xib, you'll see there is no way
to set this class in the class dropdown. So, I can't set the view manually by
loading a nib here in the init and I can't set this class as the class to be
used in the nib.
*/
}
}
上面代码中的注释解释了该问题。有趣的是,在xib中我可以看到GenericTableViewCell
作为类下拉列表中的一个选项,由于通用T: Configurable
无法设置,因此该功能无法正常工作。
可能答案是&#34;不适用于Objective-c类,&#34;但希望我错了。有任何想法吗?