Skip to content

Include example how to access time stamp and value #61

Open
@timbms

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions