Pre loader

Is there plans for better SwiftUI support?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

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?

Version
4.4.2
  • You must to post comments
0
0

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:

  1. 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.

  2. Then we configure SCIChartSurface the old-fashioned imperative way.

  3. 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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.