Skip to content

Instantly share code, notes, and snippets.

@OctoberHammer
Created May 28, 2017 18:01
Show Gist options
  • Save OctoberHammer/b77f7bdaccb8e3badca7a60a2599bb07 to your computer and use it in GitHub Desktop.
Save OctoberHammer/b77f7bdaccb8e3badca7a60a2599bb07 to your computer and use it in GitHub Desktop.
Modify Value for a certain key of a Dictionary
//: 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment