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 dictionarylet dict = ["a" : "Apple","b" : "Beta","c" : "coding","d" : "developer","e" : "edpresso"]// get the mirrorprint(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
Mirrorof the dictionary using thecustomMirrorand print the result to the console.