I work on a SwiftUI project that has integrated SciCharts.
What I’ve noticed is that while there are SwiftUI examples available, they are rather basic and when I replicate the example code over in my project, it does not run as we expect and in some cases does not run at all.
Currently there seems to be issues with the SwiftUI run loop, SwiftUI’s use of structs, and SciCharts use of pointers that make building complex charts within complex user interfaces rather challenging.
I needed to do a lot of work to get the SwiftUI example code to work in my project, and we’re still facing some challenges. Can we expect better SwiftUI support in the future, such as SwiftUI views included in the SDK or if this work has been done can the documentation be linked?
- You must login to post comments
Hi Tyler
There aren’t any plans at the moment to develop further SwiftUI views on top of SciChart.iOS
Users can still use SciChart in SwiftUI simply as follows:
-
Begin by declaring a SurfaceView struct, which conforms to the UIViewRepresentable protocol. Import SciChart, instantiate a SCIChartSurface, add axes, renderable series, and other elements to
your SCIChartSurface. -
Then we configure SCIChartSurface the old-fashioned imperative way.
-
Finally import this into your application
import SwiftUI
import SciChart
struct SurfaceView: UIViewRepresentable {
func makeUIView(context: Context) -> SCIChartSurface {
let surface = SCIChartSurface()
let xAxis = SCINumericAxis()xAxis.growBy = SCIDoubleRange(min: 0.05, max: 0.05) let yAxis = SCINumericAxis() yAxis.growBy = SCIDoubleRange(min: 0.05, max: 0.05) let count = 1000 let xValues = SCIDoubleValues(capacity: count) let yValues = SCIDoubleValues(capacity: count) for i in 0 ..< count { let x: Double = 10.0 * Double(i) / Double(count) let y: Double = sin(2 * x) xValues.add(x) yValues.add(y) } let dataSeries = SCIXyDataSeries(xType: .double, yType: .double) dataSeries.append(x: xValues, y: yValues) let renderableSeries = SCIFastLineRenderableSeries() renderableSeries.dataSeries = dataSeries SCIUpdateSuspender.usingWith(self.surface) { self.surface.xAxes.add(xAxis) self.surface.yAxes.add(yAxis) self.surface.renderableSeries.add(renderableSeries) } return surface } func updateUIView(_ uiView: SCIChartSurface, context: Context) {}
}
struct ContentView: View {
var body: some View {
SurfaceView()
}
}
If you’ve hit problems (you mentioned Pointers) I would like to hear more about them, specific pain points and what you did to resolve them or work around them.
SciChart.iOS underneath uses Objective-C, which is required as we interface to C++ via Objective-C++. Some of these issues may be resolvable but others may not due to the tech stack.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 10 months ago
- You must login to post comments
Please login first to submit.