What is customMirror String Property in Swift?

Overview

We can use the customMirror property of a string to return the mirror that reflects the String instance.

Syntax

string.customMirror

Return value

This property returns the mirror that reflects the string string.

Example

Let’s look at the code below:

// create some strings
let name = "Theodore"
let language = "Swift"
let emptyString = ""
// get customMirror property
let debugDesc1 = name.customMirror
let debugDesc2 = language.customMirror
let debugDesc3 = emptyString.customMirror
// print results
print(debugDesc1)
print(debugDesc2)
print(debugDesc3)

Explanation

  • Lines 2 to 4: We create some string values.
  • Lines 7 to 9: We get the customMirror properties of the strings we created.
  • Lines 12 to 14: We print the results 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