gpt4 book ai didi

ios - 快速获取字典中数组的值

转载 作者:可可西里 更新时间:2023-11-01 00:16:28 24 4
gpt4 key购买 nike

所以我有一个数组作为我在字典中的一个键的值,我想获取它以将其设置为 UITableViewCell 的文本。我如何得到它?我一直在使用 Objective-C 编写代码,并且开始学习 Swift。

var content: [String: Any] = ["content": ["North America", "Europe West", "Europe Nordic & East", "Oceania", "Russia", "Turkey", "Brazil", "Latin America North", "Latin America South"], "footer": "Select the League of Legends region for this app to use."]

autoreleasepool { () -> () in
var temp = self.content["content"]
cell.textLabel?.text = temp[indexPath.row] as String
}

这会返回 2 个错误 '_??' is not convertible to 'int''<<error type>>?' is not convertible to 'int'

最佳答案

您应该将字典值声明为 AnyObject。您还应该使用 if let 来解包您的可选值:

let content: [String:AnyObject] = ["content": ["North America", "Europe West", "Europe Nordic & East", "Oceania", "Russia", "Turkey", "Brazil", "Latin America North", "Latin America South"], "footer": "Select the League of Legends region for this app to use."]

if let temp = content["content"] as? [String] {
cell.textLabel!.text = temp[indexPath.row]
}

关于ios - 快速获取字典中数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30815455/

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