我有一个
我正在尝试使用以下结构读取数组:
plist
,它是一个字典的数组(根为数组)。每个字典肯定有两个值:name
和icon
作为Strings
。但有些字典有更多的键/值,有些则没有。我正在尝试使用以下结构读取数组:
struct Config: Decodable {
private enum CodingKeys: String, CodingKey {
case name, icon
}
let name: String
let icon: String
}
func functionsStruct() -> Config {
let url = Bundle.main.url(forResource: "FunctionsList", withExtension: "plist")!
let data = try! Data(contentsOf: url)
let decoder = PropertyListDecoder()
return try! decoder.decode(Config.self, from: data)
}
我阅读了一本字典,学习了如何阅读字典数组和如何设置结构。
如何解决某些字典具有其他字典不具备的键的问题?
let someProperty: String?
。 - Mike Taverne[Config].self
不起作用? - Cristik