Get the size of a dictionary

 Problem

I have a Dictionary and want to calculate its size/capacity (how many key-value pairs it contains).



 Recipe


// Initialize the Dictionary
var dict = ["name": "John", "surname": "Doe"]

// Get the size of the dictionary

let size = dict.count
print(size)
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground