swiftios8

Convert Swift Dictionary to String


For testing and debugging I am trying to put the content of Dictionary to a String. But have no clue hows it going to achieve. Is it possible? If yes, how.

Dictionary is fetched from web service so I have no idea the key values it have. I want to use the data in app.

In Objective C %@ was enough to store anything in NSString.


Solution

  • Just use the description property of CustomStringConvertible as

    Example:

    Note: Prior to Swift 3 (or perhaps before), CustomStringConvertible was known as Printable.