Add Item to a Dictionary in Swift

First, let’s create a Dictionary with two elements.

var myDictionary = ["first_name": "Sergey", "last_name": "Kargopolov"]

Now we can add a new key with a value.

myDictionary["user_id"] = "f5h7ru0tJurY8f7g5s6fd"

We should now have 3 key-value pairs printed


For more Swift code examples and tutorials, please check the Swift Code Examples page on this website.

Leave a Reply

Your email address will not be published.