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 strings
let name = "Theodore"
let language = "Swift"
let emptyString = ""
// get debugDescription property
let debugDesc1 = name.debugDescription
let debugDesc2 = language.debugDescription
let debugDesc3 = emptyString.debugDescription
// print results
print(debugDesc1) // "Theodore"
print(debugDesc2) // "Swift"
print(debugDesc3) // ""

Explanation

  • Lines 2 to 4: We create some string values.
  • Line 7 to 9: We get the debugDescription properties of the strings we created.
  • Lines 12 to 14: We print the results.

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