我有这个结构,:
// MARK: - JsonAPIData
struct JsonAPIData: Codable {
let data: [String: APIData]
let success: Bool
}
// MARK: - Datum
struct APIData: Codable, Identifiable {
let id = UUID()
let maxVersion, minVersion: Int
}
我想使用这些结构在 SwiftUI 中创建数据列表。我试过这个:
struct ContentView: View {
@State var results: JsonAPIData
var body: some View {
List(results.data.values) { data in
Text("\(data)")
}
.onAppear {
self.loadData()
}
}
func loadData() {
//My code to load `results`
}.resume()
}
}
但我有这个错误:
Initializer 'init(_:rowContent:)' requires that 'Dictionary<String, APIData>.Values' conform to 'RandomAccessCollection'
我该如何解决 listkeys
和values
of 的问题APIData
?