gpt4 book ai didi

arrays - 如何查询 (String, Dictionary) 到 UITableViewCell 中?

转载 作者:行者123 更新时间:2023-11-30 10:04:05 24 4
gpt4 key购买 nike

所以我有一个变量,其数据结构是(字符串,字典)

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"])

所以我不需要“hSmfumVmjkmg9bOYxV67”字符串,而只需要将其附带的字典放入新变量中(这样我就可以在我的 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

最佳答案

希望我正确理解你的问题。看来您有一个字典字典,您首先将其转换为数组,然后下标以获取不带“外部键”的内部字典之一?您应该能够仅使用内部字典值来创建初始音频数组。像这样:

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

关于arrays - 如何查询 (String, Dictionary<String, String>) 到 UITableViewCell 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37036644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com