What is dictionary.customMirror in Swift?

Overview

The customMirror property of a dictionary returns a Mirror that reflects that dictionary. A Mirror in Swift is used to show the parts that make up a particular object. The object could be a string, double, or dictionary value. The parts it will show can be the object’s stored properties, collection, and so on.

Syntax

dictionary.customMirror

Return property

The property returned is the Mirror for the dictionary (for example, dict).

Code example

// create a dictionary
let dict = [
"a" : "Apple",
"b" : "Beta",
"c" : "coding",
"d" : "developer",
"e" : "edpresso"
]
// get the mirror
print(dict.customMirror)

Code explanation

  • Lines 2–8: We created a dictionary dict. Then, we initialize it with some key-value pairs.

  • Line 11: We got the Mirror of the dictionary using the customMirror and print the result to the console.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources