Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include example how to access time stamp and value #61

Open
timbms opened this issue Feb 8, 2023 · 1 comment
Open

Include example how to access time stamp and value #61

timbms opened this issue Feb 8, 2023 · 1 comment

Comments

@timbms
Copy link

timbms commented Feb 8, 2023

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.

@srebhan
Copy link
Member

srebhan commented Aug 28, 2024

@timbms a PR adding such an example would be welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants