【发布时间】:2021-05-01 20:39:33
【问题描述】:
我正在尝试创建一个包含以下数据的复杂字典:
let teamInfo = [teamId : [teamInit, teamLogo]]
let gameInfo = [gameId : [gameStatus : status]]
let temp = NSMutableDictionary(dictionary: teamInfo)
temp.addEntries(from: gameInfo)
complexDictionary[weekId] = temp
我正在尝试这样声明我的 complexDictionary,但有问题:
var complexDictionary = [String : [String : [String : String]], [String : [Bool : Bool]]] ()
【问题讨论】:
-
你能提供更多关于你的“问题”的细节吗?但是,实际上,您不应该在 Swift 中使用
NSMutableDictionary。您也可能不应该使用字典中的字典。你应该使用结构。[Bool:Bool]的意义何在? -
@Paulw11 你可能是对的,我还在学习说话的绳索。你能用结构来澄清你的意思吗?
-
从长远来看,确实结构可能更好,但知道如何使用 Swift
Dictionary(又名[AnyHashable: Any]可能是有益的第一步developer.apple.com/documentation/swift/dictionary
标签: ios swift dictionary