Created
May 28, 2017 18:01
-
-
Save OctoberHammer/b77f7bdaccb8e3badca7a60a2599bb07 to your computer and use it in GitHub Desktop.
Modify Value for a certain key of a Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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