Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Ios 如何检查返回的对象是否为Swift中的数组_Ios_Swift - Fatal编程技术网

Ios 如何检查返回的对象是否为Swift中的数组

Ios 如何检查返回的对象是否为Swift中的数组,ios,swift,Ios,Swift,我有一份申报单 var cabResults = Dictionary<CabType, [CabResult]>() 现在我还想检查self.cabResults[currentCabType]返回的对象是否属于[CabResult] 我怎样才能得到这个..?如果让我。。。作为: if let cabs = self.cabResults[currentCabType] as? [CabResult] { // yep } else { // nope } 您不

我有一份申报单

var cabResults = Dictionary<CabType, [CabResult]>()
现在我还想检查self.cabResults[currentCabType]返回的对象是否属于
[CabResult]


我怎样才能得到这个..?

如果让我。。。作为

if let cabs = self.cabResults[currentCabType] as? [CabResult] {
    // yep
} else {
    // nope
}

您不需要检查对象是否为will,而需要检查任何特定类型的对象是否为will,您只需执行以下操作:

if let myObject = self.cabResults[currentCabType] as? [CabResult] {
    // myObject is not till and is of type myObject
} else {
    // the object is nil or it's not of type myObject
}
如果varName是数组{…}
if let myObject = self.cabResults[currentCabType] as? [CabResult] {
    // myObject is not till and is of type myObject
} else {
    // the object is nil or it's not of type myObject
}