Swift Dictionary keys

The keys property returns just the keys of the dictionary.

Example


keys Syntax

The syntax of the dictionary keys property is:

dictionary.keys 

Here, dictionary is an object of the Dictionary class.


keys Return Values

The keys property returns an array of all the keys of dictionary.


Example 1: Swift Dictionary keys

Output

["Sinner", "Nadal", "Alcaraz"]

In the above example, we have used the keys property to return an array of just the keys of the information dictionary.


Example 2: Using keys With for Loop

Output

Nadal
Alcaraz
Sinner

Here, we have used the for loop to iterate through all the keys of the informations dictionary.

Finally, all the keys of informations are printed one at a time.