Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I want to get the fname when I try below code it shows the error like **error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
**

let ni = sectionArray[0]
let mi = ni["sectionData"] as! [String:String]
let sh = mi["fname"]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you cannot cast ni["sectionData"] as! [String:String]
because it is not an array of [String:String] and you should not use !.

Try this:

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")
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading