如何查询(String,Dictionary <string,string =“”>)到UITableViewCell?

时间:2016-05-04 19:43:03

标签: arrays swift uitableview dictionary

所以我有一个变量,谁的数据结构是(String,Dictionary)

let audio = Array(self.sharedRec.audioDic) // Dictionary<String, Dictionary<String, String>>
let audioSet = audio[1] // (String, Dictionary<String, String>)

所以我的问题是我无法将Dictionary<String, String>(从let audioSet = audio[1])转换为另一个变量。

以下是print(audioSet)显示的内容:

("hSmfumVmjkmg9bOYxV67", ["audioString": "/hSmfumVmjkmg9bOYxV67", "audioURL": "/Users/xx/Library/Developer/CoreSimulator/Devices/67D6480B-566D-425B-88AD-E5DECC080337/data/Containers/Data/Application/7091A4BF-9E5F-4957-A3D8-ACE1D160826D/Documents/hSmfumVmjkmg9bOYxV67", "projectTitle": "Gold King", "audioTitle": "Dog"])

所以我不需要&#34; hSmfumVmjkmg9bOYxV67&#34;字符串,但只有它附带到新变量中的字典(所以我可以在我的UITableViewCell中迭代它)

像这样:

let cell.audioTitle = audioPiece.audioTitle
let cell.audioURL = audioPiece.audioURL

谢谢!

更新

感谢史蒂夫的惊人回答,我要删除不需要的密钥,只将字典变成变量。

let audio = Array(self.sharedRec.audioDic.values)
self.sharedRec.audioDic = audio
print("Inner Dicitonary Values \(audio)")

// This is what gets printed from above

[["audioString": "/iFDNtXmmvC3lbKPkk2YY", "audioURL": "/Users/xx/Library/Developer/CoreSimulator/Devices/67D6480B-566D-425B-88AD-E5DECC080337/data/Containers/Data/Application/834019D6-5223-47AE-A51E-FFA49FFB14F5/Documents/iFDNtXmmvC3lbKPkk2YY", "projectTitle": "Kash - Oh", "audioTitle": "GOAT"], ["audioString": "/tyddrt0PrrwebN5RBNy2", "audioURL": "/Users/xx/Library/Developer/CoreSimulator/Devices/67D6480B-566D-425B-88AD-E5DECC080337/data/Containers/Data/Application/834019D6-5223-47AE-A51E-FFA49FFB14F5/Documents/tyddrt0PrrwebN5RBNy2", "projectTitle": "Kash - Oh", "audioTitle": "Gold"]]

所以现在我的问题是如何迭代这两个或者(如果有更多字典的话,稍后更多)并为我的UITableViewCell获取数据?

我试过 - cell.vocalString.text = audio[0]["audioTitle"],但它说Index out of Range

1 个答案:

答案 0 :(得分:1)

希望我能正确理解你的问题。看来你有一个词典词典,你首先要转换成一个数组,然后下标得到一个没有“外键”的内部词典?您应该只使用内部字典值创建初始音频数组。像这样:

let audio = Array(self.sharedRec.audioDic.values)