******* TestData.swift ************************
struct Measures: Identifiable {
let id = UUID()
var dataSeq: Int
var value: Double
}
struct Items: Identifiable {
let id = UUID()
var name: String
var measures: [Measures]
}
struct chartItemInfo: Identifiable {
var id = UUID()
var testItem: String
var value: Double
}
var angleItem : [chartItemInfo]?
var degreeItem : [chartItemInfo]?
var grip1Item : [chartItemInfo]?
var grip2Item : [chartItemInfo]?
class TestData: ObservableObject {
@Published var angleItem : [chartItemInfo]?
@Published var degreeItem : [chartItemInfo]?
@Published var grip1Item : [chartItemInfo]?
@Published var grip2Item : [chartItemInfo]?
}
******** CalculatorViewModel.swift ******************************************
class CalculatorViewModel : NSObject, ObservableObject, Identifiable {
....
typealias test_Array = (time: String, swingNum: Int, dataSeqInSwing: Int, timeStampInSeq: Int, angle: Double, degree: Double, grip1: Double, grip2: Double)
....
@Published var testDBdata = [test_Array]()
@Published var chartDBdata = [chart_Array]() //
@StateObject var testData : TestData
var Testitems = [ (channel: "angle", data: testData.angleItem), (channel: "degree", data: testData.degreeItem), (channel: "grip1", data: testData.grip1Item), (channel: "grip2", data: testData.grip2Item)]. => Cannot use instance member 'testData' within property initializer; property initializers run before 'self' is available ?
- purpose of this project: read FMDB data and then make Array with DB data.
and then i use these Array for displaying multi plot in Chart.