Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Taylor Quinn
Taylor Quinn
20,003 Points

Help debugging exc_bad_acess

So i am building a two page tabbed app. I am using the Charts framework to put charts in my app. Both page have the same chart with different data in each. When I run the app the first page and chart display fine but when I try to run the second page and chart it crashes and I get an exc_bad_access error. here is my code

@IBOutlet weak var yourRankRetailLabel: UILabel!

@IBOutlet weak var barChartView2: BarChartView!

var employee: [String]!
var currentRank = ""

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

        DataService.dataService.CURRENT_USER_REF.observeEventType(FEventType.Value, withBlock: { snapshot in //snap

        let rank = snapshot.value.objectForKey("rankretail") as! String

        self.yourRankRetailLabel.text = "You were ranked \(rank) in service sales last week!"
        self.currentRank = rank
        }, withCancelBlock: { error in

    employee = ["1491", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    let unitsSold = [5.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]

    setChart(employee, values: unitsSold)


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


func setChart(dataPoints: [String], values: [Double]) {
    barChartView2.noDataText = "You need to provide data for the chart."

    var dataEntries: [BarChartDataEntry] = []
    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
    let chartData = BarChartData(xVals: employee, dataSet: chartDataSet)
    barChartView2.data = chartData
Steven Deutsch
Steven Deutsch
21,046 Points

Hey Taylor Quinn,

Can you post the top part of the debugger output?

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

it looks like barChartView2 is not being instantiated before you access it

Taylor Quinn
Taylor Quinn
20,003 Points

Could you please elborate on what that is and how to go about fixing it.