influxdb-client-swift icon indicating copy to clipboard operation
influxdb-client-swift copied to clipboard

Include example how to access time stamp and value

Open timbms opened this issue 1 year ago • 0 comments

It would be great if you could add an example on how to access time stamp and values most effectively. I came up with the following setup

var dataPoints = [DataPoint]()
do {

    try records?.forEach {
        if let time = $0.values["_time"] as? Date, let values = $0.values["_value"] as? Double {
            dataPoints.append(DataPoint(date: time, value: values))
        }
    }
} catch {
    print (error)
}

to fill DataPoint to be used in SwiftUI Charts.

struct DataPoint: Identifiable {
    var date: Date
    var value: Double
    var id = UUID()
}

Maybe this could be done more elegantly. It would great to have your thoughts.

timbms avatar Feb 08 '23 21:02 timbms