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 stringslet name = "Theodore"let language = "Swift"let emptyString = ""// get customMirror propertylet debugDesc1 = name.customMirrorlet debugDesc2 = language.customMirrorlet debugDesc3 = emptyString.customMirror// print resultsprint(debugDesc1)print(debugDesc2)print(debugDesc3)
Explanation
- Lines 2 to 4: We create some string values.
- Lines 7 to 9: We get the
customMirrorproperties of the strings we created. - Lines 12 to 14: We print the results to the console.