1

I have been working on finding the source of this error for many hours and am unable to do so. The error appears after I try to select the first value from a pickerview with a button. I am working with the Charts 3.0 pod. I have included the function below.

func barChartUpdate() {
    var dataEntries: [BarChartDataEntry] = []
    let moodRatings = getRatingsFromDatabase()
    for i in 0..<moodRatings.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: Double(moodRatings[i].rating))
        dataEntries.append(dataEntry)
    }
    let chartDataSet = BarChartDataSet(values: dataEntries, label: "Mood Ratings")
    do{
        let chartData = BarChartData(dataSet: chartDataSet)
        barChartView.data = chartData //Error occurs here
    } catch{
        print("error")
    }
}
  • 3
    `barChartView` is likely nil. Probably because you haven't hooked up the outlet to the view in IB or aren't correctly instantiating your view controller. – dan Jan 04 '18 at 16:00
  • Try using [Exceptional Breakpoint](https://stackoverflow.com/a/17802723/3411787). – Mohammad Zaid Pathan Jan 04 '18 at 16:23

1 Answers1

0

In case your barChartView variable is declared with an ! after type specification (at the end of line) - make sure it's intialized somewhere earlier than first call of barChartUpdate()

SwiftStudier
  • 2,272
  • 5
  • 21
  • 43