Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

swift
description
communitycreator

What is the description property in Swift?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The description property of a String instance in Swift is used to return the value of a string.

Syntax

string.description

Return value

This property returns the value of the string string.

Code example

// create some strings
let name = "Theodore"
let language = "Swift"
let emptyString = ""
// get description property
let des1 = name.description
let des2 = language.description
let des3 = emptyString.description
// print results
print(des1) // Theodore
print(des2) // Swift
print(des3) // nil
Get the "description" property of some strings in Swift

Code explanation

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

RELATED TAGS

swift
description
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring