Swift 如何在数组中存储类
我想检查一个对象是否属于某种类型。为此,我可以使用Swift 如何在数组中存储类,swift,Swift,我想检查一个对象是否属于某种类型。为此,我可以使用is检查单个类型 if cell is UITableViewCell{ // do something } 然而,我正在处理各种类型的问题。因此,我想创建一个数组来存储类的类型 let types = [ ATableViewCell, BTableViewCell, CTableViewCell] 然后在数组上迭代并检查 for type in types{ if cell is type{ // do s
is
检查单个类型
if cell is UITableViewCell{
// do something
}
然而,我正在处理各种类型的问题。因此,我想创建一个数组来存储类的类型
let types = [ ATableViewCell, BTableViewCell, CTableViewCell]
然后在数组上迭代并检查
for type in types{
if cell is type{
// do something
}
}
问题是如何将类型的类型存储到数组中。Swift 2允许我这样做吗
谢谢。我找到了解决办法。以下是有关的解决方案
我找到了解决办法。以下是有关的解决方案
let types = [ ATableViewCell.self, BTableViewCell.self, CTableViewCell.self]
for type in types{
if cell.dynamicType === type{
// do something
}
}