Bojan Salaj
Bojan Salaj

Reputation: 21

How do I dump the contents of a dictionary into a UITextView or UILabel?

I am trying to display the contents of a dictionary into either a UITextView or UILabel. I can successfully do it using println() but when trying to add the values to a .text property it only adds the first line.

for (x, y) in dict
{
    println("\(x): \(y)")
    display.text = "("\(x): \(y)") // prints only first item
    display.text = "\(dict)" // prints [item1: 1, item2: 2....] I need it on separate lines and no []. 
}

Upvotes: 2

Views: 1116

Answers (1)

JAL
JAL

Reputation: 42449

I'm not exactly sure what you're asking. Are you asking for "(x: y)" on multiple lines in a string? Use the newline escape character:

var fullDict = ""

for (x, y) in dict {
    fullDict += "(\(x): \(y))\n"
}

display.text = fullDict

Upvotes: 2

Related Questions