Ios can';我无法从NSArrayM获得号码

Ios can';我无法从NSArrayM获得号码,ios,arrays,swift,int,Ios,Arrays,Swift,Int,我在尝试从查询中检索密钥名时遇到以下错误。然后将其转换为viewcontroller使用的int Could not cast value of type '__NSArrayM' (0x1073ebdb0) to 'NSNumber' (0x1069f3488). 这是查询中的行: tempVarLDS = object.value(forKey: keyName) 打印时返回 ( 7 ) 所以它是一个数组。但我似乎无法通过网络访问它 tempvarLDS[0] 或者任何一个普通的

我在尝试从查询中检索密钥名时遇到以下错误。然后将其转换为viewcontroller使用的int

Could not cast value of type '__NSArrayM' (0x1073ebdb0) to 'NSNumber' (0x1069f3488).
这是查询中的行:

tempVarLDS = object.value(forKey: keyName)
打印时返回

(
  7
)
所以它是一个数组。但我似乎无法通过网络访问它

tempvarLDS[0]

或者任何一个普通的嫌疑犯。你知道如何得到这个整数吗?

如果它是一个NSNumbers数组,你应该能够将它转换为一个整数数组

// Cast it
let tempvarLDS:[Int] = object.value(forKey: keyName) as! [Int]

// Loop
for num in tempvarLDS {
    print(num)
}

我不明白为什么这样做行不通

当您尝试
tempvarLDS[0]
时发生了什么?为什么您要使用
NSArray
而不是Swift数组?这肯定是解析查询的结果!很乐意帮忙。