无法将类型为'[(String)]'的值分配给'String!'类型的值?

Mil*_*dic 3 dictionary textview ios swift

woodText.text = [String](textForWood.values)这是我的代码.woodText是一个UITextView,textForWood是一本字典.请帮忙.

Mun*_*ndi 6

woodText.text = textForWood["Oak"] as! String
Run Code Online (Sandbox Code Playgroud)

你需要一个字符串分配给textUITextView.以上显示了如何从Dictionary中提取String.

根据评论添加

我不认为使用字典填充表格视图是个好主意.(请记住,字典不是有序的,数组是.)你应该有一个类型的数组,通知表视图它应显示多少行以及在这些行中显示的内容.

一种解决方案是字典数组([[String : String]]).然后,您可以填充每个单元格cellForRowAtIndexPath.每行的字典应包含类似的内容

["name" : "Oak", "text" : "The text to display in the oak cell..."]
Run Code Online (Sandbox Code Playgroud)

使用标准样板代码使用文本视图使单元格出列然后

let woodDictionary = textForWood[indexPath.row]!
woodText.text = woodDictionary["text"] as! String
Run Code Online (Sandbox Code Playgroud)