swift 修改词典的某个键的值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 修改词典的某个键的值相关的知识,希望对你有一定的参考价值。

//: Playground - noun: a place where people can play

import UIKit
import Foundation

var dictOfProductsForCategory: [Int: [[String:Any]]] = [:]

//I want dictOfProductsForCategory[3183] eventually to be set with 4-items Array
//How can I do this?
var result1: [[String:Any]]? = [["id":5, "title": "Some Title"], ["id":6, "title": "Another Title"]]

var result2: [[String:Any]]? = [["id":7, "title": "Third Title"], ["id":8, "title": "Fourth Title"]]


dictOfProductsForCategory[3183] = result1
print(dictOfProductsForCategory)
dictOfProductsForCategory[3183] += result2 //Error
dictOfProductsForCategory[3183] = dictOfProductsForCategory[3183] +result2 //Error too
// How?

以上是关于swift 修改词典的某个键的值的主要内容,如果未能解决你的问题,请参考以下文章

如何比较Swift中的两个词典?

我如何获取 Firestore 数据库 iOS Swift 中对象键的值

从另一个字典更改子字典的键值 - Python

将本地向量复制到映射中某个键的值时遇到段错误

swift实现遍历嵌套字典并修改其中的值

swift实现遍历嵌套字典并修改其中的值