我有以下变量:
var params = [
"long": lon,
"lat": lat,
"radius": radius,
"deleted": "false"
]
我想为它添加一个新对:
"username": "blablah"
我该怎么办?
我尝试过:
params.setValue("blablah", forKey: "username")
但它引发了错误:
...this class is not key value coding-compliant for the key username.'
答案 0 :(得分:4)
两个问题。首先,编译器没有足够的信息来确定字典类型,因此应该指定它。此外,使用下标表示法来设置新值。见下文:
var params: [String : Any] = [
"long": lon,
"lat": lat,
"radius": radius,
"deleted": "false"
]
params["username"] = "blablah"