内容が任意のタイプ(辞書、配列、文字列など)のjsonオブジェクトを取り、タイプに基づいてオブジェクトを変更する関数があります。
以下の不自然な関数「foo」の例では、辞書を適切に変更するにはどうすればよいですか? コンパイラ エラーが発生します。
error: '@lvalue $T6' is not identical to '(String, String)'
ここに関数があります
func foo (var item: AnyObject) {
// ... other logic that handles item of other types ...
// here I know for sure that item is of [String:String] type
(item as? [String:String])?["name"] = "orange"
// error: '@lvalue $T6' is not identical to '(String, String)'
}
var fruits = ["name": "apple", "color": "red"]
foo(fruits)