What is debugDescription property of a String in Swift?
Overview
We can use the debugDescription property on a string instance to return the representation of the string suitable for debugging.
Syntax
string.debugDescription
Return value
This property returns the representation of the string suitable for debugging.
Example
Let’s look at the code below:
// create some stringslet name = "Theodore"let language = "Swift"let emptyString = ""// get debugDescription propertylet debugDesc1 = name.debugDescriptionlet debugDesc2 = language.debugDescriptionlet debugDesc3 = emptyString.debugDescription// print resultsprint(debugDesc1) // "Theodore"print(debugDesc2) // "Swift"print(debugDesc3) // ""
Explanation
- Lines 2 to 4: We create some string values.
- Line 7 to 9: We get the
debugDescriptionproperties of the strings we created. - Lines 12 to 14: We print the results.