Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在数组中存储类_Swift - Fatal编程技术网

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
    }
}