字典中字典和数组的可选更改

时间:2019-05-15 00:49:26

标签: swift

以下错误:
致命错误:展开一个可选值时意外发现nil

我认为此错误是由可选的更改方法引起的(例如使用?和!)

我变了吗?和!几次。 请说明解决此问题的想法...

let roadMap = [
    "home": ["hair": 5, "super": 10, "academy": 9],
    "hair": ["home": 5, "super": 3, "bank": 11],
    "superMarket":["hairShop":3, "home":10, "englishAcademy":7, "restourant":3],
    "englishAcademy": ["home":9, "superMarket":7, "school":12]]

var fastWay: [String: [Any]] = [:]
for i in roadMap.keys{
    fastWay.updateValue([0, 9999, "Start"], forKey: i)}

for i in roadMap["home"]!.keys {
    if fastWay[i]![0] as! Int == 0 && fastWay[i]![1] as! Int > fastWay["home"]![1] as! Int + roadMap["home"]![i]! {
        fastWay[i]![1] = fastWay["home"]![1] as! Int + roadMap["home"]![i]!
        fastWay[i]![2] = "home"
            }}

print ("fastWay = \(fastWay)", "\n")

错误:执行被中断,原因:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)。 该过程已被中断,请使用“ thread return -x”返回到表达式求值之前的状态。

0 个答案:

没有答案