iOS-Charts error: Thread1: EXC_BAD_ACCESS (code=2, address=0x2a0c220)
<p>So, I'm following the iOS-Charts tutorial on AppCoda, I followed it perfectly, then when I was having issues I also copied the code to match their exactly. </p>

<p>The problem is, when I try and create a pie chart, then run it. I get the error:</p>

<blockquote>
  <p>Thread1: EXC_BAD_ACCESS (code=2, address=0x2a0c220)</p>
</blockquote>

<p>and the app crashes. When it crashes, it highlights this line:</p>

<pre><code>pieChartView.data = pieChartData
</code></pre>

<p>Here is as screen shot of the screen:</p>

<p><a href="https://i.stack.imgur.com/jELGZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jELGZ.png" alt="screen shot"></a></p>

<p>Here is the full code from the viewcontroller.swift:</p>

<pre><code>import UIKit
import Charts

class ViewController: UIViewController {

@IBOutlet weak var pieChartView: PieChartView!

func setChart(dataPoints: [String], values: [Double]) {

    var dataEntries: [ChartDataEntry] = []

    for i in 0..&lt;dataPoints.count {
        let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: "Units Sold")
    let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
    pieChartView.data = pieChartData

    var colors: [UIColor] = []



    for i in 0..&lt;dataPoints.count {
        let red = Double(arc4random_uniform(256))
        let green = Double(arc4random_uniform(256))
        let blue = Double(arc4random_uniform(256))

        let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
        colors.append(color)
    }

    pieChartDataSet.colors = colors




}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
    let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0]

    setChart(months, values: unitsSold)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}
</code></pre>