Skip to main content
 首页 » 编程设计

Swift Dictionary 不打印键值

2024年01月01日56zhujiabin

我是 swift 编程的新手。我已经编写了以下用于迭代和打印字典的代码

var items_price = [ 
"milk": 1 , 
"bread" : 3, 
"egg" : 2 
] 
 
for (myKey, myValue) in items_price { 
      println ("\(myKey) costs : \(myValue)") 
} 

此代码不会将结果打印为“牛奶成本:1”等。怎么了?

请您参考如下方法:

println 语句打印在 Playground 的时间轴中。按打印语句行末尾圆圈中的“+”。