swift

What is the difference between debugDescription and description methods of an array in swift?


Swift documentation says

debugDescription = A textual representation of self, suitable for debugging
description = A textual representation of self

in playground i get the output of both call as same

anArray.debugDescription // "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
anArray.description // "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

What is the actual difference between the two ?


Solution

  • From Apple documentation:

    an object's debug description is the same as its description. However, you can override debugDescription if you want to decouple these; many Cocoa objects do this.

    So basically unless you add any extra functionality to your debugDescription it will be the same as description.