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
}