Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
communitycreator

What is dictionary.customMirror in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)
Get the custom mirror of a dictionary in Swift

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.

RELATED TAGS

swift
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring