cannot subscript a value of type 'inout' [String :Double] (aka inout Dictionary)

后端 未结 1 1302
青春惊慌失措
青春惊慌失措 2020-12-12 04:07

How can if i try to add three menus in the dictionary i wont let me and throws an error when i try to force unwrap the 3rd item in the menu. However if i force unwrap two of

相关标签:
1条回答
  • 2020-12-12 04:49

    You can alway iterate through and add to total, much simpler that a line of long addition.

    var totalCost: Double = 0
    for each in menu {
        totalCost += each.value
    }
    print(totalCost)
    
    0 讨论(0)
提交回复
热议问题