-1

I use in my app library SwiftChart and I want to create such view of chart:

enter image description here

My code:

    class MyViewController: UIViewController, ChartDelegate {
  override func viewDidLoad() {
    lineChart.delegate = self
  }
// Chart delegate
func didTouchChart(_ chart: Chart, indexes: Array<Int?>, x: Double, left: CGFloat) {
    // Do something on touch
}

func didFinishTouchingChart(_ chart: Chart) {
    // Do something when finished
}

func didEndTouchingChart(_ chart: Chart) {
    // Do something when ending touching chart
}

func didTouchChart(chart: Chart, indexes: Array<Int?>, x: Double, left: CGFloat) {
    for (seriesIndex, dataIndex) in enumerate(indexes) {
        if dataIndex != nil {
            // The series at `seriesIndex` is that which has been touched
            let value = chart.valueForSeries(seriesIndex, atIndex: dataIndex)
        }
    }
}

But I received and error message:

Use of unresolved identifier 'enumerate'

What's wrong?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Best Moments
  • 131
  • 2
  • 11

1 Answers1

1

Change your code snippet inside "didTouchChart" function to:

for (seriesIndex, dataIndex) in indexes.enumerated() {
        if dataIndex != nil {
            // The series at `seriesIndex` is that which has been touched
            let value = chart.valueForSeries(seriesIndex, atIndex: dataIndex)
        }
}

This is the correct syntax from swift 3 and onwards.

sinner
  • 483
  • 3
  • 14