What is the debugDescription property of a dictionary in Swift?

Overview

When we use the debugDescription property of a dictionary instance on a dictionary, we want to get the string that represents the contents of that dictionary. This property is useful and suitable for debugging.

Syntax

dictionary.debugDescription

Return value

The value returned is a string.

Code example

// create some dictionaries
var days = [
0 : "Sunday",
1 : "Monday",
2 : "Tuesday",
3 : "Wednesday",
4 : "Thursday",
5 : "Friday",
6 : "Saturday"
]
// get the debug description
print(days.debugDescription)

Explanation

  • Lines 2 to 10: We create a dictionary called days. We then give it some entry values.
  • Line 13: We get the debug description using the debugDescription property and print the value 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