How To Add Key Value To Dictionary | iSwift Cookbook

Comments · 385 Views

Learn how to add key value to Dictionary in iswift.

“A Dictionary is a collection of key-value pairs.. In order to add another key with a value, we can do it pretty much like changing an already existing key, that is: by using the subscript along with the value's key and assign it the desired value.


// Let's initialize our test dictionary

var user = [
"name" : "John",
"surname" : "Doe",
"email" : "info@iswift.org"
]

// OK, let's add some more info”

“user["nationality"] = "US"

// And print the result

print("User: \(user)")”

“User: ["name": "John", "surname": "Doe", "email": "info@iswift.org", "nationality": "US"]”

Comments