From the class below how do I initialize chartEntry for the structure array? As it is below chartEntry is outside scope of init?
class ChartSeriesRow: ObservableObject {
var id = UUID()
var chartCategory: String
struct chartSeriesData{
var chartEntry: [ChartData]
}
struct ChartData: Codable, Identifiable, Hashable {
var id = UUID()
let chartMonth: String
let chartSales: String
}
init() {
chartCategory = ""
chartEntry = chartSeriesData: [ChartData.chartMonth: "01", ChartData.chartSales: "10.0"]
}
}
I don't understand what you write here (= then :)
chartEntry = chartSeriesData: [ChartData.chartMonth: "01", ChartData.chartSales: "10.0"]
In addition, you need to declare a car of type ChartSeriesData (starting with Uppercase).
This should work:
class ChartSeriesRow: ObservableObject {
var id = UUID()
var chartCategory: String
struct ChartSeriesData {
var chartEntry: [ChartData]
}
var chartSeries : ChartSeriesData
struct ChartData: Codable, Identifiable, Hashable {
var id = UUID()
let chartMonth: String
let chartSales: String
}
init() {
chartCategory = ""
// chartEntry = ChartSeriesData : [ChartData.chartMonth: "01", ChartData.chartSales: "10.0"]
chartSeries = ChartSeriesData(chartEntry: [ChartData(chartMonth: "01", chartSales: "10.0") ] )
}
}
and yields (in playground):
- ChartSeriesData(chartEntry: [__lldb_expr_1.ChartSeriesRow.ChartData(id: 2AA6BEB0-EBFA-404D-A0C3-48FDD043CE50, chartMonth: "01", chartSales: "10.0")])