var airports : [String:String] = ["DXB" : "dubai international airport", "LHR" : "heathrow international airport"]
for (airportCode,airportName) in airports
{
airportName = airportName.capitalized
}
例如,我需要将所有值大写,但我得到了错误
“无法赋值:airportName是let常量
最佳答案
只需在for循环中添加var
var airports : [String:String] = ["DXB" : "dubai international airport", "LHR" : "heathrow international airport"]
for (var airportCode,var airportName) in airports
{
airportName = airportName.capitalized
airports[airportCode] = airportName
}