执行被中断,原因:信号 SIGABRT。带字典的二维数组-swift
Execution was interrupted, reason: signal SIGABRT. 2D Array with dictionary-swift
var sectionArray:[[String:Any]] = [ ["sectionName":"Time Cards To Approve","sectionData": [["fname":"true detective","date":"may 20"],["fname":"abbas","date":"may 10"]],"expanaded":false], ["sectionName":"Message Log","sectionData":[["movie":"true detective","event":"Bring food","date":"May 19"],["movie":"false detective","event":"no shoot today","date":"may 20"]],"expanaded":false] ]
我想在尝试下面的代码时获取 fname,它显示类似 **error: Execution was interrupted, reason: signal SIGABRT 的错误。
进程一直停留在被中断的地方,使用"thread return -x" to return 到表达式求值前的状态。
**
let ni = sectionArray[0]
let mi = ni["sectionData"] as! [String:String]
let sh = mi["fname"]
你不能施放ni["sectionData"] as! [String:String]
因为它不是 [String:String]
的数组,你不应该使用 !
.
试试这个:
if let mi = ni["sectionData"] as? [[String:String]] {
print("---> mi: \(mi) ")
let sh1 = mi[0]["fname"]
let sh2 = mi[1]["fname"]
print("---> sh1: \(sh1) \n")
print("---> sh2: \(sh2) \n")
}
你当然也可以使用for循环,比如:
if let mi = ni["sectionData"] as? [[String:String]] {
for i in mi.indices {
print("---> sh: \(mi[i]["fname"]) ")
}
}
var sectionArray:[[String:Any]] = [ ["sectionName":"Time Cards To Approve","sectionData": [["fname":"true detective","date":"may 20"],["fname":"abbas","date":"may 10"]],"expanaded":false], ["sectionName":"Message Log","sectionData":[["movie":"true detective","event":"Bring food","date":"May 19"],["movie":"false detective","event":"no shoot today","date":"may 20"]],"expanaded":false] ]
我想在尝试下面的代码时获取 fname,它显示类似 **error: Execution was interrupted, reason: signal SIGABRT 的错误。 进程一直停留在被中断的地方,使用"thread return -x" to return 到表达式求值前的状态。 **
let ni = sectionArray[0]
let mi = ni["sectionData"] as! [String:String]
let sh = mi["fname"]
你不能施放ni["sectionData"] as! [String:String]
因为它不是 [String:String]
的数组,你不应该使用 !
.
试试这个:
if let mi = ni["sectionData"] as? [[String:String]] {
print("---> mi: \(mi) ")
let sh1 = mi[0]["fname"]
let sh2 = mi[1]["fname"]
print("---> sh1: \(sh1) \n")
print("---> sh2: \(sh2) \n")
}
你当然也可以使用for循环,比如:
if let mi = ni["sectionData"] as? [[String:String]] {
for i in mi.indices {
print("---> sh: \(mi[i]["fname"]) ")
}
}