0

I'm trying to implement the touch to show the current value. The problem is that I'm getting use of unresolved identifier "value" when I try to add the text to my label. The series are shown correctly in the Chart but I'm not getting the value inside the indexes.

func didTouchChart(_ chart: Chart, indexes: [Int?], x: Float, left: CGFloat) {
        if dataResponse.count > 0 {
            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)
                let date = dataDates[dataIndex!]
                let type = SensorType.getSpecialCharacter(sensorTypes[dataIndex!])
                lblValue.text = "\(value)\(type) \(date)" //Ex. 78°C 12-11-2018
              }

            }
        }

    }

It used to work fine before, but I don't know what happened. I don't know what could be happening, I was expecting this behavior. 660d660e-9adc-11e5-8a67-0c3036c20862

After a couple of runs and cleans the error changed to Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file. I must say I don't have any file variable nor class in my code.

koen
  • 5,383
  • 7
  • 50
  • 89
Jalil
  • 1,167
  • 11
  • 34
  • you mean `let value = chart.valueForSeries(seriesIndex, atIndex: dataIndex)` is executing successfully but `lblValue.text = "\(value)\(type) \(date)"` is producing error. Right? – Keshu R. Jan 10 '20 at 18:27
  • @iOSArchitect.com nope. The error is produced in `lblValue.text = "\(value)\(type) \(date)" ` – Jalil Jan 10 '20 at 18:29
  • Well, I don't see any errors. Might sounds silly, but did you try cleaning and rebuilding your project. It works sometimes :) – Keshu R. Jan 10 '20 at 18:34
  • @iOSArchitect.com :c didn't work – Jalil Jan 10 '20 at 18:51
  • @iOSArchitect.com I even did it with if let for it not to crash, but it always has "something" – Jalil Jan 10 '20 at 19:17
  • Instead of `if dataIndex != nil`, try `if let dataIndex = dataIndex { ... }`, and change `dataIndex!` to `dataIndex`. – koen Jan 10 '20 at 20:35
  • At the end I dissociated the view's class and associated again and it worked – Jalil Jan 10 '20 at 20:40
  • @Jalil for future readers, could you describe your solution in detail in an answer? – koen Jan 10 '20 at 22:24

0 Answers0