29 Nov 2017

How to add two NSDictionaries in Swift...

   The below code is an example of adding two dictionaries,
    
    var dict1 = ["One": "1","Two": "2","Three": "3","Four": "4"]
    let dict2 = ["Five": "5","Six": "6","Seven": "7","Eight": "8"]
    dict2.forEach { (k,v) in dict1[k] = v }
    print("Combined dictionary ===> ",dict1)
    
    And the Result is,
    

Result: Combined dictionary ===>  ["Two": "2", "Five": "5", "Three": "3", "Four": "4", "Six": "6", "One": "1", "Eight": "8", "Seven": "7"]

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0