Can't assign value of type '[(String)]' to value of type 'String!'?

woodText.text = [String](textForWood.values)

This is my code. woodText

- this UITextView

, and textForWood

- a dictionary. Please, help.

+3


source to share


2 answers


woodText.text = textForWood["Oak"] as! String

      

You need to assign String to text

for UITextView

. The above shows how to extract a string from a dictionary.

Add based on comments

I don't think using a dictionary to populate the table view is a good idea. (Remember, dictionaries are not ordered, arrays.) You must have an array that informs the table of how many rows to display and what to display in those rows.



One solution would be an array of dictionaries ( [[String : String]]

). Then you can fill each cell in cellForRowAtIndexPath

. The dictionary for each line should contain something like

["name" : "Oak", "text" : "The text to display in the oak cell..."]

      

Use the standard template code to delete a cell with a text view and then

let woodDictionary = textForWood[indexPath.row]!
woodText.text = woodDictionary["text"] as! String

      

+6


source


try this:

var string = ""

for value in textForWood.values.array {
    string = string.stringByAppendingString("\(value), ")
}

woodText.text = string

      



hope this helps.

-1


source







All Articles