相关疑难解决方法(0)

将局部变量转换为可变变量

我在操场上制作的这段代码代表了我的问题:

import Foundation

var countries = ["Poland":["Warsaw":"foo"],"England":["London":"foo"]]

for (country, city) in countries {
  if city["London"] != nil {
   city["London"] = "Piccadilly Circus" // error because by default the variables [country and city] are constants (let)
  }
} 
Run Code Online (Sandbox Code Playgroud)

有没有人知道一项工作或最好的方法来使这项工作?

swift

5
推荐指数
1
解决办法
3426
查看次数

标签 统计

swift ×1